RELAX NG 外部引用中需要一点递归
我们一直在使用 RELAX NG 为基于 Web 的 API 指定和验证 XML 消息,我正在做一些清理工作并开始使用
元素。
在我们的架构中,我们有一个
元素,其中包含 id 和句点等内容,还有一个
。在 RELAX NG 中规范这一点非常简单:
<?xml version="1.0"?>
<element name="subscription" xmlns="http://relaxng.org/ns/structure/1.0">
<element name="id">
<text />
</element>
<zeroOrMore>
<externalRef href="./account.xml" />
</zeroOrMore>
</element>
然后,该模式将包含在特定请求的实际消息模式中。
问题是
元素还可以有多个
元素,具体取决于请求(例如,有时我们正在搜索订阅数据)基于帐户信息,有时我们会根据订阅数据搜索帐户信息)。
我尝试过:
<?xml version="1.0"?>
<element name="account" xmlns="http://relaxng.org/ns/structure/1.0">
<element name="id">
<text />
</element>
<zeroOrMore>
<externalRef href="./subscription.xml" />
</zeroOrMore>
</element>
但是在加载架构时遇到了一个(并非意外的)错误:Detected an externalRef recursion
有没有办法指定某种递归限制 - 有某种方法可以知道我当前的
是
的子级,因此本身不应该有
子级吗?
We've been using RELAX NG to specify and validate XML messages for our web-based API, and I was doing some housecleaning and started to make use of the <external>
element.
In our schemas we have a <subscription>
element, which has things like id and a period and so on, and also an <account>
. This is pretty simple to spec in RELAX NG:
<?xml version="1.0"?>
<element name="subscription" xmlns="http://relaxng.org/ns/structure/1.0">
<element name="id">
<text />
</element>
<zeroOrMore>
<externalRef href="./account.xml" />
</zeroOrMore>
</element>
This schema would then be included by the actual message schema for a particular request.
The problem is that the <account>
element can also have a number of <subscription>
elements depending on the request (for example, sometimes we are searching for subscription data based on account information, and sometimes we would be searching for account information based on subscription data).
I tried:
<?xml version="1.0"?>
<element name="account" xmlns="http://relaxng.org/ns/structure/1.0">
<element name="id">
<text />
</element>
<zeroOrMore>
<externalRef href="./subscription.xml" />
</zeroOrMore>
</element>
But I got a (not unexpected) error when loading the schema: Detected an externalRef recursion
Is there a way to specify some kind of recursion limit - some way to know that my current <subscription>
is a child of <account>
and so should not have <account>
children itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您指向第一个 Relax NG 中定义的
subscription
元素,子结构就必须与您指向的模式匹配。为了实现您的目标,您应该为具有不同子结构的另一个
subscription
元素定义另一个模式。类似于:
并使用
ref
元素从您的account
元素中引用 if 。As long as you point to the
subscription
element defined in you first Relax NG, the substruture has to match the pattern you are pointing to.To achieve your goal, you should have another pattern definition for another
subscription
element with a different substructure.Something like :
And refer to if from your
account
element with aref
element.