Java Reference
In-Depth Information
identifies the target namespace for the schema, and the second value ( recipe.xsd )
identifies the location of the schema within this namespace.
Note SchemafilesthatconformtoXMLSchema'sgrammararecommonlyassigned
the .xsd file extension.
If an XML document declares a namespace ( xmlns default or xmlns: prefix ),
thatnamespacemustbemadeavailabletotheschemasothatavalidatingparsercanre-
solveallreferencestoelementsandotherschemacomponentsforthatnamespace.We
alsoneedtomentionwhichnamespacetheschemadescribes,andwedosobyincluding
the targetNamespace attributeonthe schema element.Forexample,supposeour
recipe document declares a default XML namespace, as follows:
<?xml version="1.0"?>
<recipe xmlns="http://www.tutortutor.ca/">
At minimum, we would need to modify Listing 10-9 's schema element to include
targetNameSpace and the recipe document's default namespace as tar-
getNameSpace 's value, as follows:
<xs:schema targetNamespace="http://www.tutortutor.ca/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
Perhaps you're wondering why you need to learn about XML Schema when DTD
shouldbegoodenoughforyourXMLprojects.ThereasonforlearningXMLSchemais
that Chapter11 introducesyoutotheXML-basedWebServicesDescriptionLanguage
(WSDL), and the WSDL example that's presented in that chapter includes an XML
Schema-based schema.
Parsing XML Documents with SAX
Simple API for XML (SAX) isanevent-basedAPIforparsinganXMLdocumentsequen-
tiallyfromstarttofinish.AsaSAX-orientedparserencountersanitemfromthedocu-
ment's infoset (anabstractdatamodeldescribinganXMLdocument'sinformation—see
http://en.wikipedia.org/wiki/XML_Information_Set ) , it makes this
itemavailabletoanapplicationasan event ,bycallingoneofthemethodsinoneofthe
application's handlers (anobjectwhosemethodsarecalledbytheparsertomakeevent
information available), which the application has previously registered with the pars-
er.Theapplicationcanthen consume thiseventbyprocessingtheinfosetiteminsome
manner.
Search WWH ::




Custom Search