【发布时间】:2014-09-16 20:48:23
【问题描述】:
当且仅当method/key 中的id=* 和method/call 中的{*} 子字符串存在双射时,我想验证XML。
-
有效,因为每个
{*}都与id=*完全对应 反之亦然。<format> <call> /tags/{1}/top-askers/{2} </call> <key id="1"> <name>tag</name> <discussion>a tag for the site</discussion> </key> <key id="2"> <name>period</name> </key> </format> -
无效,因为有一个
id=*没有对应的{*}。<format> <call> /tags/{1} </call> <key id="1"> <name>tag</name> <discussion>a tag for the site</discussion> </key> <key id="2"> <name>period</name> </key> </format> -
无效,因为有一个
{*}没有对应的id=*。<format> <call> /tags/{1}/top-askers/{2} </call> <key id="1"> <name>tag</name> <discussion>a tag for the site</discussion> </key> </format> -
理想情况下,我也希望这也是可能的,这意味着
{*}的内容可以是[^}{]中的任何一个。<format> <call> /tags/{tag}/top-askers/{2} </call> <key id="tag"> <name>tag</name> <discussion>a tag for the site</discussion> </key> <key id="2"> <name>period</name> </key> </format>
我查看了 XML 模式的 w3schools 参考,但它似乎没有列出任何此类功能。不过,这当然不是规范的完整参考。这在 XML 模式中是否可行?
更新
@JirkaŠ 提供了以下表达式,它解决了 (2) (和 (4)) 但不是 (3):
for $key in /format/key
return matches($key/../call,
concat("\{", $key/@id, "\}"))
【问题讨论】:
标签: xml validation xpath xsd