是否可以使用 Schema 在 XML 文档中定义根元素? [英] Is it possible to define a root element in an XML Document using Schema?
本文介绍了是否可以使用 Schema 在 XML 文档中定义根元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能吗?我不知道该怎么做.
Is this possible? I can't work out how to do it.
推荐答案
以下应该有效,我还建议 W3 Schools 部分的模式.
The following should work, I'd also suggest the W3 Schools section on schemas.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="rootElement" type="RootElementType"/>
<xs:complexType name="RootElementType">
<xs:sequence>
<xs:element name="child1" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="child2" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="user" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>
这应该是这样的 XML 结构的架构:
This should be the schema for an XML structure like this:
<rootElement user="Bob">
<child1>Hello</child1>
<child1>World</child1>
<child2>Optional</child2>
</rootElement>
这篇关于是否可以使用 Schema 在 XML 文档中定义根元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文