放松NG验证 - 如何允许通用属性
我正在设计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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的临时想法:
一样定义您的通用属性
您可以像需要通用属性引用的元素
my adhoc idea:
you can define your universal attribute like
The elements that need the universal attribute reference it