Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

XML Unique Key Validation problem with XML Schema

so797109asMar 19 2009 — edited Mar 19 2009
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.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 16 2009
Added on Mar 19 2009
6 comments
422 views