Jump to content
rsfm

schema key used with namespace

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>

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...