Proper way to define xsd schema in my situation
<Item id="G1@MIT" type="开发者_如何学GoGROUP">
<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?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.
精彩评论