Onetx
Onetx

Reputation: 88

XSD validating attribute is equal to a parent attribute

I need to create an XSD that validates the value in a specific complex type with a parent node.

In this specific case the XML will look like this:

<ROOT>
  <INFO>
      <REGIONDESC>
        <REGION VALUE="001" DESCRIPTION="Description 1" />
        <REGION VALUE="002" DESCRIPTION="Description 2" />
        <REGION VALUE="003" DESCRIPTION="Description 3" />    
      </REGIONDESC>
      ...Other Nodes..
  </INFO>
  <DETAILS>
      <REGIONDETAILS>
        <REGIONID VALUE="001"/>
        ...Other Nodes..
      </REGIONDETAILS>
  </DETAILS>
</ROOT>

I need validate that "REGIONID" value must be equal to some "REGIONDESC/REGION@VALUE". Is it possible?

Upvotes: 0

Views: 86

Answers (1)

Michael Kay
Michael Kay

Reputation: 163322

In the definition of the ROOT element, define an xs:key with selection xpath="INFO/REGIONDESC/REGION", and field xpath="@VALUE"; and a corresponding xs:keyRef with selection xpath="DETAILS/REGIONDETAILS/REGIONID" and field xpath="@VALUE".

Upvotes: 2

Related Questions