Ok so, basically what I currently have is:XSD:\[code\]<?xml version="1.0"?><xsd:schema xmlns="test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="test" elementFormDefault="qualified"> <xsd:complexType name="fields"> <xsd:choice minOccurs="1" maxOccurs="unbounded"> <xsd:element name="text"> <xsd:complexType> <xsd:attribute name="id" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> <xsd:element name="group"> <xsd:complexType> <xsd:sequence> <xsd:element name="fields" type="fields"/> </xsd:sequence> <xsd:attribute name="id" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> </xsd:choice> </xsd:complexType> <xsd:element name="root"> <xsd:complexType> <xsd:sequence> <xsd:element name="fields" type="fields" minOccurs="0" maxOccurs="unbounded"> <xsd:key name="fieldId"> <xsd:selector xpath=".//*"/> <xsd:field xpath="@id"/> </xsd:key> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element></xsd:schema>\[/code\]XML:\[code\]<?xml version="1.0" encoding="UTF-8"?><root xmlns="test"> <fields> <text id="asd"/> <text id="sdf"/> <group id="dfg"> <fields> <text id="asd"/> <text id="sdf"/> </fields> </group> </fields></root>\[/code\]Clearly XML is not valid according to XSD since there are ID's that are duplicate, but the problem is, that I want the id's to be validated only in their own scope, in other words this should fail:\[code\]<?xml version="1.0" encoding="UTF-8"?><root xmlns="test"> <fields> <text id="asd"/> <text id="asd"/> </fields></root>\[/code\]while this should pass:\[code\]<?xml version="1.0" encoding="UTF-8"?><root xmlns="test"> <fields> <text id="asd"/> <group id="sdf"> <fields> <text id="asd"/> </fields> </group> </fields></root>\[/code\]Just to make it clear, I'm planning to prepend the parent ID to the child ID when parsing the XML and therefore I don't care about nested ID's being duplicates while their not in the same scope since I want to be able to achieve similar results to:\[code\]<?xml version="1.0" encoding="UTF-8"?><root xmlns="test"> <fields> <group id="eventA_time"> <fields> <text id="hour"/> <text id="minute"/> <text id="second"/> </fields> </group> <group id="eventB_time"> <fields> <text id="hour"/> <text id="minute"/> <text id="second"/> </fields> </group> </fields></root>\[/code\]