views:

18

answers:

1
<Item id="G1@MIT" type="GROUP">
   <Item id="B1@MIT" type="BLOCKSEGMENT"/>
   <Item id="S1@MIT" type="SWITCH"/>
</Item>

xml content above is an example of my xml data. As you see I have Items that can contain other items.
My first question is how to define xml schema in this situation.
My second question is I want my id attribute to contain '@' character.
How can I achieve this?

+1  A: 

Defining recursive structures in XML Schema is trivial. It's just a matter of defining a type that contains an element of that type:

<xs:complexType name="ItemType">
  <xs:sequence minOccurs="0">
    <xs:element name="Item" type="ItemType"></xs:element>
  </xs:sequence>
</xs:complexType>

Attributes can contain the @ character by default without any issues. If you want to force the attribute to contain that character then you should read up on XML Schema restrictions. In particular you'll want to look at the xs:pattern element.

Welbog