Is it possible to restrict an IDREF attribute so that it only matches child ID values?

Unanswered Is it possible to restrict an IDREF attribute so that it only matches child ID values?

  • 5. srpna 2012 18:53
     
      Obsahuje kód

    Suppose I have the following XML snippet:

    <x child="value">
      <y id=z/>
    </x>
    I want to ensure that "x/@child" is limited, in this case, to "z".  ("value" is a placeholder.")  How do I do that?


    Will Pittenger

Všechny reakce

  • 6. srpna 2012 9:28
     
      Obsahuje kód

    I saw http://stackoverflow.com/questions/891324/xsd-key-keyref-hierarchical-key-structure.  In there they talked about this sample of code (translated to use the above names):

    <xs:element name="x">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="y">
            <xs:complexType>
              <xs:attribute name="id" type="NAME"/>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
        <xs:attribute name="child" type="NAME"/>
        <xs:key name="child-name">
          <xs:selector xpath="x/y"/>
          <xs:field xpath="../@id"/>
          <xs:field xpath="@id"/>
        </xs:key>
      </xs:complexType>
    </xs:element>

    They noted how ".." isn't allowed in field xpaths, which I verified.  But in a flash of what I hope was insight, I changed the xpaths.  Compare this code with what is above:

    <xs:element name="x">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="y">
            <xs:complexType>
              <xs:attribute name="id" type="NAME"/>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
        <xs:attribute name="child" type="NAME"/>
        <xs:key name="child-name">
          <xs:selector xpath="x"/>
          <xs:field xpath="@id"/>
          <xs:field xpath="y/@id"/>
        </xs:key>
      </xs:complexType>
    </xs:element>

    The question now is, will that cause the XSD to do what I want?  I am concerned the "y/@id" will only take one child per parent.  Next, do I put the <xs:keyref> inside the <xs:attribute> element?  Or somewhere else?


    Will Pittenger