Hiiiiiii
During working with XML and XML schema, I am getting a problem during the Unique Key Validation of XML schema.
XSD file
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.anshinsoft.com"
xmlns="http://www.anshinsoft.com"
elementFormDefault="qualified">
<xsd:element name="UserDetails">
<xsd:complexType >
<xsd:sequence>
<xsd:element name="USER" maxOccurs="unbounded" type="USER"/>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="un_name">
<xsd:selector xpath="USER"/>
<xsd:field xpath="."/>
</xsd:unique>
</xsd:element>
<xsd:complexType name="USER">
<xsd:sequence>
<xsd:element name="userId" type="xsd:int"/>
<xsd:element name="UserName" type="xsd:string"/>
<xsd:element name="Password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
XML File :
<?xml version="1.0"?>
<UserDetails
xmlns="http://www.anshinsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.anshinsoft.com UserAuthentication.xsd">
<USER>
<userId>1</userId>
<UserName>QF</UserName>
<Password>1234</Password>
</USER>
<USER>
<userId>2</userId>
<UserName>XX</UserName>
<Password>XX</Password>
</USER>
<USER>
<userId>3</userId>
<UserName>anshin</UserName>
<Password>123</Password>
</USER>
</UserDetails>
The objective of the schma is to validate the XML file and also check is all the values are unique under <USER> tag or not. My program will validate the XML with XSd through apache.XMLBean API and also with javax.Schema API.