XSD 元素名称模式匹配 [英] XSD element name pattern matching

查看:27
本文介绍了XSD 元素名称模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作 XSD 以验证我从 Web 服务返回的一些 XML.它看起来像这样:

I'm trying to make an XSD to validate some XML I'm getting back from a web service. It looks something like this:

<values>
    <value_1>asdf</value_1>
    <value_2>asdf</value_2>
    <value_3>asdf</value_3>
    <value_4>asdf</value_4>
    <value_5>asdf</value_5>
</values>

内部值节点的数量是无限的,但它们总是以_ + number 后缀结尾.是否可以编写一个 XSD 来验证节点名称本身?

The number of inner value nodes is unbounded, but they always end with the _ + number suffix. Is it possible to to write an XSD that validates the node names themselves?

推荐答案

XSD 1.1 解决方案

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="values">
    <xs:complexType>
        <xs:sequence>
            <xs:any maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:assert test="every $e in * 
                         satisfies matches(local-name($e), 'value_[0-9]+')"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

这篇关于XSD 元素名称模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆