tags:

views:

22

answers:

1

Is it possible to write an XML Schema that describes an XML document that lists a set of elements and then requires other elements on that same XML document to use those values as either attributes and/or sub-elements?

Example: define a list of locations, then force location attributes and/or location elements to be of those values.

<root>
  <locations>
    <location>Home</location>
    <location>Office</location>
    <location>School</location>
  </locations>
  <addresses>
    <address location="Home">...</address>
    <address location="Office">...</address>
  </addresses>
</root>

or

<root>
  <locations>
    <location>Home</location>
    <location>Office</location>
    <location>School</location>
  </locations>
  <addresses>
    <address>
      <location>Home</location>
      ...
    </address>
    <address>
      <location>Office</location>
      ...
    </address>
  </addresses>
</root>

I am failing hard at finding the proper way to search for this information. I suspect it is either not possible or I just don't know the right search terms.

+1  A: 

XML Schema in its current version 1.0 cannot help you here. You cannot model any dependencies between nodes and their values ("if node X has a value of ABC, then there must be a "ABC" node somewhere else in the XML document"), I'm afraid.

There are other XML validation mechanisms, such as Schematron or Relax NG which sometimes can do things XML Schema can't do. You might want to check out those and see if you can achieve your goal using such a tool.

marc_s
Awww shucks = (
Raegx