您的位置:程序门 -> web 开发 -> xml/soap



难题:complextype能够接受任何的顺序的内容,并且允许任意扩展内容


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


难题:complextype能够接受任何的顺序的内容,并且允许任意扩展内容
发表于:2007-08-27 20:24:15 楼主
下面的xml,我想加任意的内容,并且允许任意的顺序。
<root>
        <identifier> urn:hsc:1234 </identifier>
</root>

比如:
<root>
        <a> hello </a>
        <identifier> urn:hsc:1234 </identifier>
        <b> hello </b>
</root>

定义如下的xsd:  
<xs:element   name= "root ">
      <xs:complextype>
            <xs:choice   minoccurs= "0 "   maxoccurs= "unbounded ">
                    <xs:element   name= "identifier "   type= "xs:string "/>
                    <xs:any   processcontents= "lax "   minoccurs= "0 "   maxoccurs= "unbounded "/>
            </xs:choice>
      </xs:complextype>
</xs:element>
但是出错。

如果改成:
<xs:element   name= "root ">
      <xs:complextype>
            <xs:sequence   minoccurs= "0 "   maxoccurs= "unbounded ">
                    <xs:element   name= "identifier "   type= "xs:string "/>
                    <xs:any   processcontents= "lax "   minoccurs= "0 "   maxoccurs= "unbounded "/>
            </xs:sequence>
      </xs:complextype>
</xs:element>

可以validate   成功,但是顺序又不能随意。

高手帮忙解决。谢谢
发表于:2007-08-28 10:30:081楼 得分:0
该回复于2007-12-28 16:04:48被管理员或版主删除
发表于:2007-08-28 12:36:392楼 得分:0
<?xml   version= "1.0 "   encoding= "utf-8 "?>
<xsd:schema   xmlns:xsd= "http://www.w3.org/2001/xmlschema ">
<xsd:element   name= "root ">
<xsd:complextype>
<xsd:sequence>
<xsd:any   minoccurs= "1 "   maxoccurs= "unbounded "/>
</xsd:sequence>
</xsd:complextype>
</xsd:element>
<xsd:element   name= "a "   type= "xsd:string "/>
<xsd:element   name= "b "   type= "xsd:string "/>
<xsd:element   name= "identifier "   type= "xsd:string "/>
</xsd:schema>


快速检索

最新资讯
热门点击