脚本宝典收集整理的这篇文章主要介绍了php – 在XML文档中使用XSD验证属性唯一性,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
示例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验证这一点.任何帮助非常感谢.
以上是脚本宝典为你收集整理的php – 在XML文档中使用XSD验证属性唯一性全部内容,希望文章能够帮你解决php – 在XML文档中使用XSD验证属性唯一性所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。