tags:

views:

37

answers:

2

Hello,

I know it is probably a question against XML philosophy but still is it possible to define schemata for XML like this:

<Root>
  <arbitrary-name-of-node>
   <Name></Name>
   <Position></Position>
   <!-- ... -->
  </arbitrary-name-of-node>

  <arbitrary-name-of-node>
   <Name></Name> 
   <Position></Position>
   <!-- ... -->
  </arbitrary-name-of-node>
</Root>

where arbitrary-name-of-node matches regular expression [a-zA-Z0-9]?

Thanks for an answer!

+1  A: 

I don´t think it´s possible.

The way I see it, you have two choices.

1. Create a schema like this, and add every "arbitrary-name-of-node" under the root type.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:all>
        <xs:element name="arbitrary-name-of-node1" type="itemType" />
        <xs:element name="arbitrary-name-of-node2" type="itemType" />
        <xs:element name="arbitrary-name-of-node3" type="itemType" />
      </xs:all>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="itemType">
    <xs:sequence>
      <xs:element name="Name" />
      <xs:element name="Position" />
      <!--...-->
    </xs:sequence>
  </xs:complexType>
</xs:schema>

2. Create a schema only for the content inside the "arbitrary-name-of-node" and validate each node by them selves.

Jens Granlund
Well the first way would be possible only if I know the names of nodes in advance but I don't. The second approach seems good - together with the "xs:any" (http://www.w3schools.com/schema/schema_complex_any.asp) I can validate each arbitrary node. Thanks!
MartyIX
+1  A: 
MartyIX