xml foreign key issue

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi
pls chk what is the issue on following code
i am having files "books.xsd"
<?xml version="1.0" encoding="utf-8"?><br/>
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata <br/>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true <br/>
<xs:complexType><br/>
<xs:choice minOccurs="0" maxOccurs="unbounded <br/>
<xs:element name="product <br/>
<xs:complexType><br/>
<xs:sequence><br/>
<xs:element name="id" type="xs:string" minOccurs="0" /><br/>
<xs:element name="name" type="xs:string" minOccurs="0" /><br/>
<xs:element name="price" type="xs:string" minOccurs="0" /><br/>
</xs:sequence><br/>
</xs:complexType><br/>
</xs:element><br/>
<xs:element name="sales <br/>
<xs:complexType><br/>
<xs:sequence><br/>
<xs:element name="salesid" type="xs:string" minOccurs="0" /><br/>
<xs:element name="productid" type="xs:string" minOccurs="0" /><br/>
<xs:element name="salesqty" type="xs:string" minOccurs="0" /><br/>
</xs:sequence><br/>
</xs:complexType><br/>
</xs:element><br/>
</xs:choice><br/>
</xs:complexType><br/>
<xs:unique name="Constraint1 <br/>
<xs:selector xpath=".//product" /><br/>
<xs:field xpath="id" /><br/>
</xs:unique><br/>
<xs:keyref name="relation1" refer="Constraint1 <br/>
<xs:selector xpath=".//sales" /><br/>
<xs:field xpath="productid" /><br/>
</xs:keyref><br/>
</xs:element><br/>
</xs:schema>
and product.xml as
<?xml version="1.0" encoding="utf-8" ?><br/>
<productdetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="books.xsd <br/>
<product><br/>
<id>1</id><br/>
<name>cinthol</name><br/>
<price>200</price><br/>
</product><br/>
<product><br/>
<id>2</id><br/>
<name>liril</name><br/>
<price>300</price><br/>
</product><br/>
<product><br/>
<id>3</id><br/>
<name>hammam</name><br/>
<price>400</price><br/>
</product><br/>
</productdetails>
and sales.xml as
<?xml version="1.0" encoding="utf-8"?><br/>
<salesdetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="books.xsd <br/>
<sales><br/>
<salesid>1</salesid><br/>
<productid>1</productid><br/>
<salesqty>100</salesqty><br/>
</sales><br/>
<sales><br/>
<salesid>2</salesid><br/>
<productid>2</productid><br/>
<salesqty>150</salesqty><br/>
</sales><br/>
<salesid>3</salesid><br/>
<productid>3</productid><br/>
<salesqty>160</salesqty><br/>
</salesdetails>
and i added the data in sales xml to check the foriegn key validation(x:keyref validation) as
try<br/>
{<br/>
Stream ss = new FileStream(@"sales.xml", FileMode.Append);<br/>
XmlTextWriter tw = new XmlTextWriter(ss,null);<br/>
//tw.WriteStartDocument();<br/>
//tw.WriteStartElement("salesdetails");<br/>
tw.WriteStartElement("sales");<br/>
tw.WriteElementString("salesid", "3");<br/>
tw.WriteElementString("productid", "3");<br/>
tw.WriteElementString("salesqty", "160");<br/>
tw.WriteEndElement();<br/>
//tw.WriteEndElement();<br/>
//tw.WriteEndDocument();<br/>
tw.Close();<br/>
}<br/>
catch (Exception ex1)<br/>
{<br/>
MessageBox.Show(ex1.Message.ToString());<br/>
}
but the actual foreign key validation not done, pls clear me regarding this <hr class="sig Efforts may fail but dont fail to take effort -------------- sidd

View the full article
 
Back
Top