Jump to content

schema key used with namespace


rsfm
 Share

Recommended Posts

hi, I tried using schema keys with noNamespaceSchemalocation, it worked.However, when I try to use schema keys with namespaces, it fails to detect keys not matched. The observation is as if there is no schema key declared in the schema. Below are the xml file and the schema I tried on. Please point out where I am wrong on it. Thanks ahead.testing2.xml:

<?xml version="1.0" encoding="UTF-8"?><parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	xmlns="testing2"	xsi:schemaLocation="testing2 testing2.xsd">	<registeredChild id="c123" />	<registeredChild id="c235" />	<child id="c123" />	<child id="c234" /></parent>

testing2.xsd

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"	targetNamespace="testing2"	xmlns="testing2">	<xs:element name="child">		<xs:complexType>			<xs:attribute name="id" type="xs:string" use="required" />		</xs:complexType>	</xs:element>	<xs:element name="registeredChild">		<xs:complexType>			<xs:attribute name="id" type="xs:string" use="required" />		</xs:complexType>	</xs:element>	<xs:element name="parent">		<xs:complexType>			<xs:sequence>				<xs:sequence>					<xs:element ref="registeredChild" maxOccurs="unbounded" />				</xs:sequence>				<xs:element ref="child" maxOccurs="unbounded" />			</xs:sequence>		</xs:complexType>		<xs:key name="childKey">			<xs:selector xpath="registeredChild" />			<xs:field xpath="id" />		</xs:key>		<xs:keyref name="childKeyRef" refer="childKey">			<xs:selector xpath="child" />			<xs:field xpath="@id" />		</xs:keyref>	</xs:element></xs:schema>

Link to comment
Share on other sites

sorry little correction to the code, though it still doesn't work:child elements' ids have to reference to the registered child elements' ids.testing2.xsd:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"	targetNamespace="testing2"	xmlns="testing2">	<xs:element name="child">		<xs:complexType>			<xs:attribute name="id" type="xs:string" use="required" />		</xs:complexType>	</xs:element>	<xs:element name="registeredChild">		<xs:complexType>			<xs:attribute name="id" type="xs:string" use="required" />		</xs:complexType>	</xs:element>	<xs:element name="parent">		<xs:complexType>			<xs:sequence>				<xs:element ref="registeredChild" maxOccurs="unbounded" />				<xs:element ref="child" maxOccurs="unbounded" />			</xs:sequence>		</xs:complexType>		<xs:key name="childKey">			<xs:selector xpath="registeredChild" />			<xs:field xpath="@id" />		</xs:key>		<xs:keyref name="childKeyRef" refer="childKey">			<xs:selector xpath="child" />			<xs:field xpath="@id" />		</xs:keyref>	</xs:element></xs:schema>

testing2.xml:

<?xml version="1.0" encoding="UTF-8"?><parent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	xmlns="testing2"	xsi:schemaLocation="testing2 testing2.xsd">	<registeredChild id="c123" />	<registeredChild id="c235" />	<child id="c123" />	<child id="c234" /></parent>

thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...