I am trying to verify that the attribute is unique for all elements that exist in an XML document.
XML example:
<exampleXml> <a id="1"/> <a id="2"> <b id="1"/> </a> </exampleXml>
My XSD scheme:
<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>
The xpath problem is here. I want to map each element as root, but the above xpath is above:
Element '{http://www.w3.org/2001/XMLSchemaasureselector', attribute 'xpath':
The XPath expression '//' could not be compiled
I can change the xpath to "*", but this will only check the id attribute on elements that are direct root counts.
I check this with lib_xml in PHP using DOMDocument::schemaValidate() . Any help was greatly appreciated.
source share