微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 在XML文档中使用XSD验证属性唯一性

我正在尝试验证 XML文档中存在的所有元素的属性的唯一性.

示例XML:

<exampleXml>
  <a id="1"/>
  <a id="2">
    <b id="1"/>
  </a>
</exampleXml>

我的XSD架构:

<xs:schema elementFormDefault="qualified">
  <xs:element name="exampleXml">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="a">
          <xs:complexType>
            <xs:complexContent>
              <xs:extension base="baseRuleType">
                <xs:sequence>
                  <xs:element minOccurs="0" maxOccurs="1" name="b">
                    <xs:complexType>
                      <xs:complexContent>
                        <xs:extension base="baseRuleType"/>
                      </xs:complexContent>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:extension>
            </xs:complexContent>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="duplicateIdsForbidden">
      <xs:selector xpath="//"/>
      <xs:field xpath="@id"/>
    </xs:unique>
  </xs:element>
  <xs:complexType name="baseRuleType">
    <xs:attribute name="id" use="optional"/>
  </xs:complexType>
</xs:schema>

xpath是这里的问题.我想匹配root下的每个元素,但上面的选择器xpath返回:

Element '{http://www.w3.org/2001/XMLSchema}selector',attribute 'xpath': 
The XPath expression '//' Could not be compiled

我可以将xpath更改为“*”,但这只会验证作为根的直接后代的元素的id属性.

我使用DOMDocument :: schemaValidate()在PHP中使用lib_xml验证这一点.任何帮助非常感谢.

使用< xs:selector xpath =“.//*”/>.

原文地址:https://www.jb51.cc/php/130308.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐