XML-Schema key/keyref 问题
给定以下 xml 片段:
<Environment>
...
<MySqlConfiguration>
<ActiveServer>1@db1</ActiveServer>
<PassiveServer>2@db1</PassiveServer>
<Replicate from="1@db1" to="2@db1" />
<Replicate from="2@db1" to="1@db1" />
</MySqlConfiguration>
...
</Environment>
我想将 from/to 值限制为
XSD 中 ActiveServer 或 PassiveServer 中指定的值,我尝试以下操作:
<xs:element name="Environment" type="environment" >
<xs:key name="ServerKey">
<xs:selector xpath=".//ActiveServer|PassiveServer"/>
<xs:field xpath="*"/>
</xs:key>
<xs:keyref name="ServerKeyRef" refer="ServerKey">
<xs:selector xpath=".//Replicate"/>
<xs:field xpath="@from"/>
</xs:keyref>
...
</xs:element>
但是,键中的 xpath="*"
字段选择器不起作用(它无法获取 Active/PassiveServer 元素的文本节点)。 xpath="text()"
也不起作用。执行以下操作:
<xs:element name="Environment" type="environment" >
<xs:key name="ServerKey">
<xs:selector xpath="Environment"/>
<xs:field xpath="ActiveServer|PassiveServer"/>
</xs:key>
<xs:keyref name="ServerKeyRef" refer="ServerKey">
<xs:selector xpath=".//Replicate"/>
<xs:field xpath="@from"/>
</xs:keyref>
...
</xs:element>
不起作用(字段必须引用一个实例;仅指定其中一个实例即可)。
我是否忽略了如何在字段 xpath 值中获取元素的文本内容?
Given the following xml-snippet:
<Environment>
...
<MySqlConfiguration>
<ActiveServer>1@db1</ActiveServer>
<PassiveServer>2@db1</PassiveServer>
<Replicate from="1@db1" to="2@db1" />
<Replicate from="2@db1" to="1@db1" />
</MySqlConfiguration>
...
</Environment>
I want to restrict from/to values to those specified in ActiveServer or PassiveServer
in XSD, I try the following:
<xs:element name="Environment" type="environment" >
<xs:key name="ServerKey">
<xs:selector xpath=".//ActiveServer|PassiveServer"/>
<xs:field xpath="*"/>
</xs:key>
<xs:keyref name="ServerKeyRef" refer="ServerKey">
<xs:selector xpath=".//Replicate"/>
<xs:field xpath="@from"/>
</xs:keyref>
...
</xs:element>
However, the xpath="*"
field selector in the key does not work (it does not get the text node of the Active/PassiveServer elements). xpath="text()"
does not work either. Doing something like:
<xs:element name="Environment" type="environment" >
<xs:key name="ServerKey">
<xs:selector xpath="Environment"/>
<xs:field xpath="ActiveServer|PassiveServer"/>
</xs:key>
<xs:keyref name="ServerKeyRef" refer="ServerKey">
<xs:selector xpath=".//Replicate"/>
<xs:field xpath="@from"/>
</xs:keyref>
...
</xs:element>
Does not work (field must refer to one instance; specifying just one of those would work).
Is there some way I'm overlooking on how to grab an element's text content in a field xpath value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望以下内容能够工作:
注意“|”具有最低优先级,因此需要重复“.//”。 XSD Rec 中的 BNF:
I would expect the following to work:
Note "|" has lowest precedence so the ".//" needs to be repeated. The BNF from XSD Rec: