在 XML 架构中不允许元素成为其自身的子元素
我正在为一个项目编写 XML 模式。我无法解决以下问题:
A 元素不能自行嵌套,例如:
<document>
<text>
<b>
<i>
<a link="http://wikipedia.org">
<b />
</a>
</i>
</b>
</text>
</document>
不应允许此示例,因为 b 正在嵌套自身。所以我问你的问题是:“是否有可能禁止元素嵌套自身,如果是的话,执行此操作的程序是什么?”
谢谢,有优势!
\莫滕·默勒
编辑: 到目前为止,我只确保一个元素可以是其自身的子元素,但并没有确保元素不能有其自身的后代。
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://cs.au.dk/dWebTek/WikiXML"
targetNamespace="http://cs.au.dk/dWebTek/WikiXML"
elementFormDefault="qualified">
<element name="wiki">
<complexType>
<choice maxOccurs="unbounded">
<!-- A lot of other element is listed here -->
<element name="bold" type="xs:boldnest"/> <!-- Missing nest function -->
</choice>
<complexType>
</element>
<complexType name="boldnest">
<choice maxOccurs="unbounded">
<element name="bold" minOccurs="0" maxOccurs="0" type="xs:boldnest"/>
<!-- All the other element is copy pasted in here -->
</choice>
</complexType>
Im writing a XML schema for a project. I cannot solve following problem:
A element cannot be nested by itself, ex:
<document>
<text>
<b>
<i>
<a link="http://wikipedia.org">
<b />
</a>
</i>
</b>
</text>
</document>
This example shouldn't be allow because the b is nesting itself. So my question for you is: "Is it possible to disallow a element to nest it self, and if yes whats the procedure to do the trick?"
Thx in advantage!
\Morten Møller
Edit:
Until now I only have made sure that a element can be a child of itself, but not that a element cant have a descendant that is itself.
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://cs.au.dk/dWebTek/WikiXML"
targetNamespace="http://cs.au.dk/dWebTek/WikiXML"
elementFormDefault="qualified">
<element name="wiki">
<complexType>
<choice maxOccurs="unbounded">
<!-- A lot of other element is listed here -->
<element name="bold" type="xs:boldnest"/> <!-- Missing nest function -->
</choice>
<complexType>
</element>
<complexType name="boldnest">
<choice maxOccurs="unbounded">
<element name="bold" minOccurs="0" maxOccurs="0" type="xs:boldnest"/>
<!-- All the other element is copy pasted in here -->
</choice>
</complexType>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想做的事是不可能的。在 XML 架构中,如果您使用基于类型的方法,则只能通过内容模型控制元素的子元素,而不是所有可能的后代。
您可能接近您正在尝试做的事情的唯一方法是完全定义
document
的内容到最后一层。但是你不能建立一个递归结构,然后将你正在考虑的那种约束放在适当的位置。在 XML 模式验证完成后,您需要使用其他一些机制来验证这一点。
What you are trying to do is not possible. In XML Schema, if you are using a type-based approach, you can only control the children of an element through the content model, not all possible descendants.
The only way you could possibly get close to what you are trying to do is to fully define the contents of
document
down to the last level. But you cannot establish a recursive structure and then put in place the sort of constraint you are thinking of.You will need to validate this using some other mechanism, after XML schema validation is done.