如何排除 XSD 中的根元素?
我在 XSD 文件中定义了几个元素,稍后在文档中将它们用作参考。我确实希望这些“引用”元素中的任何一个都能构成一个有效的 xml 文件。
例如,我
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Section">
<xs:complexType>
<xs:sequence>
<xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="code"/>
<xs:attribute name="url"/>
<xs:attribute name="isLegacy"/>
<xs:attribute name="name"/>
<xs:attribute name="helpFileName"/>
</xs:complexType>
</xs:element>
<xs:element name="Sections">
<xs:complexType>
<xs:sequence>
<xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
不希望验证以下 xml(如果这是文件中的唯一行)
<Section code="" url="" isLegacy="" name="" helpFileName="" />
从全局中删除“Section”节点会阻止我引用它进行递归
I have several elements defined in my XSD file that I use as references later on in the document. I do want any of these "reference" elements to constitute a valid xml file.
For example I have
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Section">
<xs:complexType>
<xs:sequence>
<xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="code"/>
<xs:attribute name="url"/>
<xs:attribute name="isLegacy"/>
<xs:attribute name="name"/>
<xs:attribute name="helpFileName"/>
</xs:complexType>
</xs:element>
<xs:element name="Sections">
<xs:complexType>
<xs:sequence>
<xs:element ref="Section" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I don't want the following xml to validate (if this is the only line in the file)
<Section code="" url="" isLegacy="" name="" helpFileName="" />
Removing the "Section" node from the global prevents me from referencing it for recursion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您愿意,请不要将这些元素声明为全局元素,而是将架构设计基于复杂类型,并仅将您想要的元素声明为根全局元素。没有人强迫你让每个元素都全球化。
例如,您的示例可以重构如下:
If you want that, don't declare these elements as global, instead, base your schema design on complex types and declare only the element you want as a root global. Nobody forces you to make every element global.
For example, your sample can be refactored as follows: