2010-09-26 69 views
0

我试图创建一个XML架构,将允许文字和元素的元素<内容>不限数量的<一个>,< b创建无限数量的无序元素的XML模式>和<c>元素。下面是一个XML示例。在混合元素

<xml version="1.0" encoding="UTF-8"?> 
<article xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="article.xsd"> 
    <content>Lorem <a>ipsum</a> dolor sit amet, consectetur adipiscing elit. Nulla rhoncus <b>laoreet neque</b> ac mollis. <a>Aliquam</a> erat <c>volutpat</c>. Nunc ante turpis, placerat eu mattis eu, egestas eu elit. 
    </content> 
</article> 

我发现很难让任何数量的这些元素以任何顺序。

回答

1

您需要使用混合内容类型。有一个简单的理解他们的描述here

事情是这样的:

<xs:element name="article"> 
    <xs:complexType mixed="true"> 
    <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element name="a" type="xs:string"/> 
     <xs:element name="b" type="xs:string"/> 
     <xs:element name="c" type="xs:string"/> 
    </xs:choice > 
    </xs:complexType> 
</xs:element> 

的部分要注意的是mixed="true",这使得文本的元素之间出现。