Hello, I am new to XML Schema, and I have a problem to enforce a sequence of elements onto the XML instance. In the example below, it is obvious, that the faulty example.xml must not validate against the syntax defined in example.xsd, because:
- Element a has to come first, then b, and at last c. XML Schema specifies that an element has to occur exactly once if no cardinality is given. But element a has not been specified. - The document is not well-formed, element b is closed with /x. But it does validate (using the SAX2 parser), at least there is no indication of an error (error or fatalError callbacks are not called). Please see below for further details. ----------------------------------------------------------------------------- XML Schema: example.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="message"> <xs:complexType> <xs:sequence> <xs:element name="a" type="xs:nonNegativeInteger"/> <xs:element name="b" type="xs:string"/> <xs:element name="c" type="xs:nonNegativeInteger"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> ----------------------------------------------------------------------------- Correct XML Instance: example.xml <?xml version="1.0" encoding="UTF-8"?> <message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='example.xsd'> <a>2</a> <b>str</b> <c>3</c> </message> ----------------------------------------------------------------------------- Faulty XML Instance: example.xml <?xml version="1.0" encoding="UTF-8"?> <message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation='example.xsd'> <b>str</x> <c>3</c> </message> ============================================================================== The XML Schema is read in and validated. Changing the line <xs:element name="a" type="xs:nonNegativeInteger"/> to <xs:element ame="a" type="xs:nonNegativeInteger"/> leads to an error as expected: SAX2Handler::error: Element must have a name or a ref attribute - element ignored at line: 6 I have tried Xerces 2.6 and 2.7 on Linux/x86-32 with the following options: m_parser = XMLReaderFactory::createXMLReader(); m_parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // default with 2.6 m_parser->setFeature(XMLUni::fgXercesSchema, true); // default with 2.6 m_parser->setFeature(XMLUni::fgSAX2CoreValidation, true); // default with 2.6 m_parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true); m_parser->setFeature(XMLUni::fgXercesDynamic, false); // default with 2.6 m_parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true); // m_parser->setFeature(XMLUni::fgXercesStandardUriConformant, true); // does not work m_parser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, true); // default with 2.6 m_parser->setProperty(XMLUni::fgXercesScannerName, (void *)XMLUni::fgSGXMLScanner); // only schema support needed The normal SAX2 handler callbacks are called (startElement, endElement, characters), which leads to a program fault. I know that attributes are optional by default, but elements have minOccurence=1 and maxOccurence=1 by default, so are required. Can someone help me? Thanks, André Heynatz
