Hi,
I'm trying to enforce primary key constraint in xsd. I'm using the following xsd to generate the xmls .
<?xml version="1.0" encoding="UTF-8"?>
<!--<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault=
"unqualified">-->
<xs:schema targetNamespace="http://TBD-URI" elementFormDefault="qualified"
attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Employees">
<xs:annotation>
<xs:documentation>Contains All Employee information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Empno" type="xs:int" />
<xs:element name="Ename" type="xs:string" />
<xs:element name="Sal" type="xs:float" />
<xs:element name="Deptno" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="PK_Employee_Empno">
<xs:selector xpath=".//Employee" />
<xs:field xpath="Empno" />
</xs:key>
</xs:element>
</xs:schema>
Here's the generated XML
<?xml version="1.0" encoding="UTF-8"?>
<Employees xmlns="http://TBD-URI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://TBD-URI file:/C:/Documents%20and%20Settings/ctsuser/workspace/JAXB/src/test/resources/TEST.xsd">
<Employee>
<Empno>0</Empno>
<Ename>Ename0</Ename>
<Sal>0</Sal>
<Deptno>0</Deptno>
</Employee>
<Employee>
<Empno>0</Empno>
<Ename>Ename1</Ename>
<Sal>0</Sal>
<Deptno>0</Deptno>
</Employee>
</Employees>
The generated XML allow the same Empno on which the primary key constraint has been defined. I'll appreciate if someone can provide pointers on how to enforce this constraint so that it doesn't allow the same Empno to be repeated.
Thanks