放松NG验证 - 如何允许通用属性

发布于 2025-01-31 08:50:40 字数 898 浏览 6 评论 0原文

我正在设计XML,以便其中的每个元素都可以指定一些通用属性。 例如,假设初始XML是:

<RootElement>
    <Sub>
        ...
    </Sub>

    <Single1/>

    <Single2/>

</RootElement>

然后以下内容也有效:

<RootElement UniversalAttr="true">
    <Sub UniversalAttr="false">
        ...
    </Sub>

    <Single1/>

    <Single2 UniversalAttr="true"/>
</RootElement>

我需要这种能力,以便以后在运行时过滤XML,基于属性值。

我知道的唯一方法是在架构中指定属性可能出现的所有可能位置。因此,以下块将在模式中多次出现:

<optional>
    <attribute name="UniversalAttr">
        <choice>
            <value>true</value>
            <value>false</value>
        </choice>
    </attribute>
</optional>

但是我正在寻找一种可以指定一旦的方法,即此属性可能会出现XML作者希望的任何元素。

可以做到吗?

编辑:第二最好的解决方案是能够定义“忽略”属性。

I'm designing my XML so that every element in it may specify some universal attribute.
For example, say the initial XML was:

<RootElement>
    <Sub>
        ...
    </Sub>

    <Single1/>

    <Single2/>

</RootElement>

Then the following is also valid:

<RootElement UniversalAttr="true">
    <Sub UniversalAttr="false">
        ...
    </Sub>

    <Single1/>

    <Single2 UniversalAttr="true"/>
</RootElement>

I need this ability for being able to later filter the XML at runtime, based on the attribute values.

The only method I know is to specify in the schema all the possible places the attribute may appear. So that the following block would appear many many times in the schema:

<optional>
    <attribute name="UniversalAttr">
        <choice>
            <value>true</value>
            <value>false</value>
        </choice>
    </attribute>
</optional>

But I'm looking for a method where I could specify once that this attribute may appear for any element the XML author wishes.

Can this be done?

EDIT: a second best solution would be to be able to define an "ignored" attribute.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

生生漫 2025-02-07 08:50:40

我的临时想法:
一样定义您的通用属性

  <define name="att.universal">
      <optional>
         <attribute name="UniversalAttr">
           <choice>
             <value>true</value>
             <value>false</value>
           </choice>
         </attribute>
      </optional>
   </define>

您可以像需要通用属性引用的元素

 <element name="xyz">
     <ref name="att.universal"/>
     ....
 </element>

my adhoc idea:
you can define your universal attribute like

  <define name="att.universal">
      <optional>
         <attribute name="UniversalAttr">
           <choice>
             <value>true</value>
             <value>false</value>
           </choice>
         </attribute>
      </optional>
   </define>

The elements that need the universal attribute reference it

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