XML 模式:可扩展容器元素
我正在尝试为具有多个命名空间的文档创建一个架构。像这样的事情:
<?xml version="1.0"?>
<parent xmlns="http://myNamespace"
xmlns:c1="http://someone/elses/namespace"
xmlns:c2="http://yet/another/persons/namespace">
<c1:child name="Jack"/>
<c2:child name="Jill"/>
</parent>
这就是到目前为止我的架构中的内容:
<xs:element name="parent" type="Parent"/>
<xs:complexType name="Parent">
<!-- don't know what to put here -->
</xs:complexType>
<!-- The type that child elements must extend -->
<xs:complexType name="Child" abstract="true">
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
计划是让其他人能够创建具有任意子元素的文档,只要这些子元素扩展我的 Child
类型。我的问题是:如何限制
元素,使其只能包含类型为 Child
类型扩展的元素?
I am trying to create a schema for a document that will have multiple namespaces. Something like this:
<?xml version="1.0"?>
<parent xmlns="http://myNamespace"
xmlns:c1="http://someone/elses/namespace"
xmlns:c2="http://yet/another/persons/namespace">
<c1:child name="Jack"/>
<c2:child name="Jill"/>
</parent>
This is what I have in my schema so far:
<xs:element name="parent" type="Parent"/>
<xs:complexType name="Parent">
<!-- don't know what to put here -->
</xs:complexType>
<!-- The type that child elements must extend -->
<xs:complexType name="Child" abstract="true">
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
The plan is for others to be able to create documents with arbitrary child elements, as long as those child elements extends my Child
type. My question is: how can I restrict the <parent>
element such that it can only contain elements whose types are extensions of the Child
type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这里找到了答案:XML 架构:最佳实践 - 可变内容容器。
显然,您可以将
声明为abstract
。解决方案如下:其他模式可以像这样定义自己的子类型:
然后我们可以将其作为有效文档:
I found the answer here: XML Schemas: Best Practices - Variable Content Containers.
Apparently you can declare
<element>
s asabstract
. A solution is as follows:Other schemas can then define their own child types like this:
We can then have this as a valid document:
请找到下面的链接。这告诉我们如何继承元素。
http://www.ibm.com/developerworks/library/x-flexschema/
Please find the link below. This tells how inherit the elements.
http://www.ibm.com/developerworks/library/x-flexschema/