2
我正在使用XSD。我想要一個container
元素(複合類型),其中包含任何基本類型爲component
的元素。xsd中的抽象
一種方法是...
<complexType name="Container">
<sequence>
<element name="Child" type="am:Component"></element>
</sequence>
</complexType>
但問題還有我的組件被稱爲兒童。假設我有3個組件,foo
,bar
和baz
。我希望能做出一個看起來像一個文件...
<container>
<foo fooTag="foo"/>
<foo fooTag="foo"/>
<baz bazTag="baz"/>
<bar barTag="bar"/>
</container>
隨着我結束了第一種方法......
<container>
<child fooTag="foo"/>
<child fooTag="foo"/>
<child bazTag="baz"/>
<child barTag="bar"/>
</container>
我可以簡單地使用xs:any
元素,但我會失去我的斷言,孩子必須是component
。有什麼方法可以得到我想要的嗎?
我怕的就是這個。感謝您的好回答和例子。 – Pace 2010-06-27 03:34:18
是的......不幸的是,對於任何來自編程觀點的人來說,這種行爲都是違反直覺的。儘管這種限制在.NET Web服務中有所體現 - 例如WSDL生成器不夠聰明,無法處理子類型,除非您明確告訴它哪些子類型是有效的(通過XmlIncludeAttribute)。 – 2010-06-27 03:37:27