views:

20

answers:

1

So, basically what I want to do is to emulate the "ref" attribute of schema validation. I have the following XML, for example:

<node name="parent">
  <subordinate name="child3" />
</node>

<node name="child1" />
<node name="child2" />      

And I want this to be flagged by my schema as invalid, since "child3" isn't one of the available 'node' options (it wasn't specified). I have the following schema:

<xs:element name="node" nillable="false">
  <xs:complexType>
    <xs:attribute ref="name" use="required" />
  </xs:complexType>
</xs:element>

<xs:element name="subordinate" nillable="false">
  <xs:complexType>
    <xs:attribute ref="name" use="required" />
  </xs:complexType>
</xs:element>

But I'm not sure how to specify that the "subordinate" element's "name" attribute must come from another defined "node" element.

Thanks for any help you can give!

A: 

I'm not an XSD expert, but I believe you want to declare the name attribute on node as an XSD type ID, and the name attribute on subordinate as an IDREF.

Edit: Added references

ID/IDREF datatypes: http://www.w3.org/TR/xmlschema-2/#ID

ID/IDREF validation: http://www.w3.org/TR/xmlschema-1/#cvc-id

Jim Garrison
Thanks much! I appreciate your help.
jwir3