xml - keyref in xsd not working -


below simplified version of xsd , xml. trying check each orderedpart@rpartid has valid match in part@partid.

all tools have tried tell me xml valid against xsd. second order should give error 67 not valid part@partid.

xsd

<?xml version="1.0" encoding="utf-8"?>  <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:tns="http://localhost" xmlns="http://localhost" targetnamespace="http://localhost" elementformdefault="qualified" attributeformdefault="unqualified" >      <xs:element name="root">     <xs:complextype>         <xs:sequence>             <xs:element name="order" type="ordertype" maxoccurs="unbounded"/>             <xs:element name="parts" type="parttype"/>         </xs:sequence>     </xs:complextype>      <xs:keyref name="dummy" refer="pnumkey">         <xs:selector xpath="tns:orderedpart" />         <xs:field xpath="@rpartid"/>     </xs:keyref>      <xs:key name="pnumkey">         <xs:selector xpath="tns:part"/>         <xs:field xpath="@partid"/>     </xs:key> </xs:element>  <xs:complextype name="ordertype">     <xs:sequence>       <xs:element name="orderedpart" maxoccurs="unbounded">           <xs:complextype>               <xs:attribute name="rpartid" type="xs:integer"/>           </xs:complextype>       </xs:element>   </xs:sequence> </xs:complextype>  <xs:complextype name="parttype">     <xs:sequence>       <xs:element name="part" maxoccurs="unbounded">           <xs:complextype>               <xs:attribute name="partid" type="xs:integer"/>           </xs:complextype>       </xs:element>   </xs:sequence> </xs:complextype> </xs:schema> 

and xml:

<?xml version="1.0" encoding="utf-8" ?>  <root xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xsi:nonamespaceschemalocation="keyrefs.xsd"  xmlns="http://localhost" > <order>     <orderedpart rpartid="1"/> </order> <order>     <orderedpart rpartid="67"/> <!-- validation should give error --> </order> <parts>     <part partid="1"/> </parts> </root> 

suspect xpaths and/or namespaces in selectors. following input other posts on site have played namespace combinations cannot work.

any advice welcome.

(updates op seem lose of xsd)

the main problem of xsd not using selectors properly. selectors relative element belong to said in xsd specs:

{selector} specifies restricted xpath ([xpath]) expression relative instances of element being declared.

for reason need change xpath selectors tns:order/tns:orderedpart , tns:parts/tns:part in order select correct elements.

in addition, using partid attribute key, defined optional attribute. not desired behaviour error if key not present, can use use="required" in attribute.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -