RELAX NG 外部引用中需要一点递归

发布于 2025-01-01 18:51:12 字数 1308 浏览 4 评论 0原文

我们一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咋地 2025-01-08 18:51:12

只要您指向第一个 Relax NG 中定义的 subscription 元素,子结构就必须与您指向的模式匹配。

为了实现您的目标,您应该为具有不同子结构的另一个 subscription 元素定义另一个模式。

类似于:

<define name="subscriptionDEF-2">
    <element name="subscription">
        <text/>
    </element>
</define>

并使用 ref 元素从您的 account 元素中引用 if 。

<element name="account">
    <ref name="subscriptionDEF-2"/>
</element>

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 :

<define name="subscriptionDEF-2">
    <element name="subscription">
        <text/>
    </element>
</define>

And refer to if from your account element with a ref element.

<element name="account">
    <ref name="subscriptionDEF-2"/>
</element>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文