1

Is it possible to write an XSD schema for XML where all node names has the same name and can only be identified by an attribute value?

A sample XML data:

<root name="func">
  <param name="User name">John Doe</param>
  <param name="Home address">
    <param name="Street 1">Some Street</param>
    <param name="number">58</param>
    <param name="geo">
      <param name="value 1">1</param>
      <param name="value 2">
        ...
      </param>
    </param>
  </param>
  <param name="Phone">
    <param name="type">cell</param>
    <param name="phone number">888 333 777</param>  
  </param>
</root>

Unfortunately, I cannot change the XML structure and set the tag names to the same value as the "name" attribute because it may contain whitespace characters and even some special characters such as exclamation marks etc.

Importantly, each nested node can also be a composite type, and its children will have a similar structure with the element name "param" and the "name" attribute identifying them.

Of course, the structure of a node's children should depend on its "name" attribute, so when we, for example, move a "phone number" tag to an "Home address" node our schema should mark such XML as invalid.

An example of invalid XML that should fail XSD Schema validation:

<root name="func">
  <param name="User name">John Doe</param>
  <param name="Home address">
    <param name="Street 1">Some Street</param>
    <param name="number">58</param>
    <param name="geo">
      <param name="value 1">1</param>
      <param name="value 2">
        ...
      </param>
    </param>
    <param name="phone number">888 333 777</param> <!-- at this line validation should fail -->
  </param>
  <param name="Phone">
    <param name="type">cell</param> 
  </param>
</root>
Gilmor
  • 439
  • 1
  • 3
  • 11

0 Answers0