Thursday, March 31, 2011

XML Schema: Restrict child element based on attribute value of parent element?

Is there any way to restrict the use of an XML element's sub elements, depending on the attribute value of the parent element in XML Schema? How does the schema have to look like?

<option name="mike" value="excset">
  <excludingsets>
    <excludingset>
      <option name="hd"/>
    </excludingset>
  </excludingsets>
</option>
<option name="mike" value="args">
  <arguments>
    <argument name="kjk" validatortype="regex">
      <regex value="dkas"/>
    </argument>
  </arguments>
</option>

As you can see in this example, the element <excludingset> should only be valid if the attribute value of <option> is value="excset", and the element <arguments> if it has value="args".

Thanks in advance.

From stackoverflow
  • Not in W3C XML Schema 1.0. You can in ISO RelaxNG and, I believe, in W3C XML Schema 1.1.

    rudimenter : unfortunately i expected this answer :-(
  • Hello... could you solve that problem I'm try to do somethig like that right now.

    Regards

0 comments:

Post a Comment