2012-04-02 116 views
1

我想創建一個*的.xsd文獻(爲一個簡單的遊戲;)),其具有說明書中:遞歸XML結構

<description>有混合元件,它有子元素I和B。它們與描述元素具有相同的類型,因此它們可以具有相同的i和b元素。

所以我想我必須創建一個遞歸結構?我的問題是如何創建這樣的結構?

回答

1

有一些令人困惑的陳述;當你說description有混合元素和」你的意思是說其他元素,如< c />和< d />或mixed,因爲它允許文本以及(認爲這裏的html標記)?當你提到i和b的內容時,是否每個都只有和the same i and b Element,或者上面的混合元素呢?

爲了實現您的案例的遞歸內容模型,我建議使用類型,而不是組;前者正在使用我所知道的大多數工具。下面是一個XSD的一個簡單的例子,支持文本(混合=「真」),從那裏你可以開始探索:

<?xml version="1.0" encoding="utf-8"?> 
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)--> 
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="description" type="descriptionType"/> 
    <xsd:complexType name="descriptionType" mixed="true"> 
     <xsd:choice minOccurs="0" maxOccurs="unbounded"> 
      <xsd:element name="b" type="descriptionType"/> 
      <xsd:element name="i" type="descriptionType"/> 
     </xsd:choice> 
    </xsd:complexType> 
</xsd:schema> 

我會在並行可視化符合的個XML,並開始調整:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<description xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">text<b>text<b>text<b>text</b> 
      <i>text</i> 
     </b> 
     <i>text<b>text</b> 
      <i>text</i> 
     </i> 
    </b> 
    <i>text<b>text<b>text</b> 
      <i>text</i> 
     </b> 
     <i>text<b>text</b> 
      <i>text</i> 
     </i> 
    </i> 
</description>