加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

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

发布时间:2020-05-25 08:31:57 所属栏目:PHP 来源:互联网
导读:我正在尝试验证 XML文档中存在的所有元素的属性的唯一性. 示例XML: exampleXml a id=1/ a id=2 b id=1/ /a/exampleXml 我的XSD架构: xs:schema elementFormDefault=qualified xs:element name=exampleXml

我正在尝试验证 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 =“.//*”/>.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读