2012-04-03 31 views
1

我有场景,我必须使用相同的XSD元素用于不同的目的,以便我的结果XML可以包含一个或多个p标签,但不是全部。如何用多个选项定义xsd元素?

<p>some paragraph here </p> 

    <p> 
     <img src = "....." alt="......"/> 
    </p> 

    <p> <b> some text here <b> <p> 

    <p> ...... <g1> ........ <g2>.......<g3>........<p> 

我是XML Schema的新手,在此先感谢。

回答

0

我正在做的假设是您试图通过显示其不同的内容模型来定义标签。首先,通过接收文本,你必须将其内容定义为混合。从那里,你可以使用重复的选择,列出了所有其他元素,如IMG,B,G1,G2等

我显示从XHTML XSD的摘录:

<xs:element name="p"> 
    <xs:complexType mixed="true"> 
     <xs:complexContent> 
     <xs:extension base="Inline"> 
      <xs:attributeGroup ref="attrs" /> 
     </xs:extension> 
     </xs:complexContent> 
    </xs:complexType> 
    </xs:element> 

    <xs:complexType name="Inline" mixed="true"> 
    <xs:annotation> 
     <xs:documentation> 
     "Inline" covers inline or "text-level" elements 
     </xs:documentation> 
    </xs:annotation> 
    <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:group ref="inline" /> 
     <xs:group ref="misc.inline" /> 
    </xs:choice> 
    </xs:complexType> 

等。

一个很好的学习可能是看看XTHML XSD。您可以使用XSD编辑器来调查与标签关联的结构。

+0

这就是我一直在寻找的!谢谢。 – Harini 2012-04-05 06:05:15