XML document specifies the XML Schema grammar location in the
xsi:schemaLocation attribute attached to the root / top-level element.
Here is an example with no target namspace:
| | |
| <?xml version="1.0" encoding="UTF-8"?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='personal.xsd'>
...
</personnel>
| |
| | |
Please see the sample file, 'samples/data/personal-schema.xml' for
further detail. And review the sample file 'samples/data/personal.xsd'
for an example of an XML Schema grammar.
Here is an example how to turn on schema processing in DOMParser
(default is off). Note that you must also turn on namespace support
(default is off) for schema processing.
| | |
| // Instantiate the DOM parser.
DOMParser parser;
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.parse(xmlFile);
| |
| | |
Usage in SAXParser is similar, please refer to the
sample program 'samples/SAXCount/SAXCount.cpp' for further reference.
Here is an example how to turn on schema processing in SAX2XMLReader
(default is on). Note that namespace must be on (default is on) as well.
| | |
| SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLString::transcode("http://xml.org/sax/features/namespaces"), true);
parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/schema"), true);
parser->parse(xmlFile);
| |
| | |