XML-Schema key/keyref 问题

发布于 2025-01-04 12:11:25 字数 1536 浏览 1 评论 0原文

给定以下 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 技术交流群。

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

发布评论

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

评论(1

一口甜 2025-01-11 12:11:25

我希望以下内容能够工作:

  <xs:selector xpath=".//ActiveServer|.//PassiveServer"/>
  <xs:field xpath="."/>

注意“|”具有最低优先级,因此需要重复“.//”。 XSD Rec 中的 BNF:

 Selector  ::=  Path ( '|' Path )*

I would expect the following to work:

  <xs:selector xpath=".//ActiveServer|.//PassiveServer"/>
  <xs:field xpath="."/>

Note "|" has lowest precedence so the ".//" needs to be repeated. The BNF from XSD Rec:

 Selector  ::=  Path ( '|' Path )*
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文