xml - Validation errors on xsd:keyref -



xml - Validation errors on xsd:keyref -

i have problem next schema want "match" jobgroup attribute of job element name attribute of jobgroup element, can't verify costraints through validation

this schema , illustration should fail

<?xml version="1.0" encoding="utf-8"?> <xs:schema targetnamespace="http://www.example.org/example" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:tns="http://www.example.org/example" elementformdefault="qualified" > <xs:element name="cluster" type="tns:clustertype"> <xs:keyref name="jobgroupkeyref" refer="tns:jobgroupkey"> <xs:selector xpath=".//job"></xs:selector> <xs:field xpath="@jobgroup"></xs:field> </xs:keyref> <xs:key name="jobgroupkey"> <xs:selector xpath=".//jobgroup"></xs:selector> <xs:field xpath="@name"></xs:field> </xs:key> </xs:element> <xs:complextype name="jobtype"> <xs:attribute name="id" type="xs:positiveinteger" use="required"/> <xs:attribute name="submissiontime" type="xs:datetime" use="required"/> <xs:attribute name="jobgroup" type="xs:string" default="default"/> </xs:complextype> <xs:complextype name="jobgrouptype"> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="description" type="xs:string" default=""/> </xs:complextype> <xs:complextype name="clustertype"> <xs:choice minoccurs="1" maxoccurs="unbounded"> <xs:element name="job" type="tns:jobtype" minoccurs="0" maxoccurs="unbounded"/> <xs:element name="jobgroup" type="tns:jobgrouptype" minoccurs="0" maxoccurs="unbounded"/> </xs:choice> <xs:attribute name="name" type="xs:string" use="required"/> </xs:complextype> </xs:schema> <cluster xmlns="http://www.example.org/example" xmlns:xs="http://www.w3.org/2001/xmlschema-instance" xs:schemalocation="http://www.example.org/example xsdfile.xsd" name="cluster1" > <job submittedhost="host1" id="1" submissiontime="2009-03-31t17:40:35.000+02:00" jobgroup="default"></job> <job submittedhost="host2" id="2" submissiontime="2009-03-31t17:40:35.000+02:00" jobgroup="wrongname"></job> <jobgroup name="default" description="job grouping number 1"></jobgroup> </cluster>

you forgot utilize qualified name in selectors. missing namespace.

try this:

<xs:element name="cluster" type="tns:clustertype"> <xs:keyref name="jobgroupkeyref" refer="tns:jobgroupkey"> <xs:selector xpath=".//tns:job"></xs:selector> <xs:field xpath="@jobgroup"></xs:field> </xs:keyref> <xs:key name="jobgroupkey"> <xs:selector xpath=".//tns:jobgroup"></xs:selector> <xs:field xpath="@name"></xs:field> </xs:key> </xs:element>

xml xsd-validation keyref

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -