I have the following simple XSD schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://test" elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:tns="http://test"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="AType">
<xs:sequence>
<xs:element name="info" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="A" type="tns:AType"/>
</xs:schema>
Is the following simple XML document valid in relation to this schema?
<?xml version="1.0" encoding="UTF-8" ?>
<X xsi:type="AType"
xmlns="http://test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<info>text</info>
</X>
I tried it in an on-line validator that uses JAXP and the default J2SE 1.7 parser, and the XML document validated successfully (http://www.utilities-online.info/xsdvalidation/). On the other hand, xmllint says that
Schemas validity error : Element '{http://test}X': No matching global declaration
available for the validation root. test2.xml fails to validate
Are they using different validation modes? Is the mode used by the J2SE parser based on the XSD specification?
Amendment to the question:
Michael Kay points me (below) to particular locations in the XSD specification. I've tried to decipher what the XSD specification says. Do I understand correctly that:
- The three assessment approaches are said "primary", so that other (arbitrary) approaches are allowed?
- In (3), if there is no matching XSD definition for the root element, lax assessment should be used. But it seems that the spec doesn't exclude elements with namespace prefix from lax assessment. While then the J2SE online validatorn fails if the element in the above example is given a namespace prefix?
- Does lax validity assession apply to the root in my example above? The root has no "context-determined declaration", has it? The definition in the spec reads:
...an element information item's schema validity may be laxly assessed if its "context-determined declaration" is not skip by "validating" with respect to the "ur-type definition"...