RE: What's a valid instance...James Clark

Hello,

(hope that this doesn't stray from the original topic -- I think it is
related)

I noticed something else regarding ambiguous root element(s):

If the XML Schema defines more than one element globally then any such
globally defined element can be a valid root to an XML instance document
of that XML Schema definition.


<?xml version="1.0"?>
<xsd:schema
		xmlns:xsd="http://www.w3.org/2001/XMLSchema"
		targetNamespace="foo"
		xmlns="foo"
		elementFormDefault="qualified">

	<xsd:element name="a" type="aType"/>

	<xsd:element name="b">
		<xsd:complexType/>
	</xsd:element>
	
	<xsd:element name="c">
		<xsd:complexType/>
	</xsd:element>

	<xsd:complexType name="aType">
		<xsd:sequence>
			<xsd:element ref="b"/>
			<xsd:element ref="c"/>
		</xsd:sequence>
	</xsd:complexType>

</xsd:schema>


So:
<?xml version="1.0"?>
<b/>

is valid against the above listed schema

but also
<?xml version="1.0"?>
<a>
	<b/>
	<c/>
</a>

And also

<?xml version="1.0"?>
<c/>



Is this intentional? I mean -- I couldn't find a way to restrict a sole
root to the document.

Shlomo.

Received on Thursday, 22 March 2007 14:44:03 UTC