how to validate XML file basing on the XSD file.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi ,
My problem is i cant check if a xml file is valid or not respecting the xsd schema . I do what is exactly shown
http://stackoverflow.com/questions/572853/xml-validation-using-xsd-schema
here but it doesnt check the unicity constraint .
XML File :
<pre class="prettyprint <?xml version="1.0" encoding="utf-8" ?>
<DataSets xmlns="http://tempuri.org/XMLSchema1.xsd" name="MaListe

<DataSet type="Uk
<user></user>
<passWord></passWord>
<stringConnexion></stringConnexion>
<DataSetQuerys id="1
<sqlString></sqlString>
</DataSetQuerys>
<DataSetQuerys id="1
<sqlString></sqlString>
</DataSetQuerys>
</DataSet>

<DataSet type="Uk
<user></user>
<passWord></passWord>
<stringConnexion></stringConnexion>
<DataSetQuerys id="1
<sqlString></sqlString>
</DataSetQuerys>
<DataSetQuerys id="1
<sqlString></sqlString>
</DataSetQuerys>
</DataSet>

</DataSets>[/code]
XSD File :
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema

<!-- Types -->

<xs:complexType name="DataSetQuery
<xs:sequence>
<xs:element name="sqlString" type="xs:string" />
</xs:sequence>
<xs:attribute name="id" type ="xs:integer" use="required"/>
</xs:complexType>


<xs:complexType name="DataSet
<xs:sequence>
<xs:element name="user" type="xs:string"/>
<xs:element name="passWord" type="xs:string"/>
<xs:element name="stringConnexion" type="xs:string"/>
<xs:element maxOccurs="16" minOccurs="1" name="DataSetQuerys" type="DataSetQuery

<xs:key name="cleUniqueOfQuery
<xs:selector xpath="."/>
<xs:field xpath="@id"/>
</xs:key>

</xs:element>
</xs:sequence>
<xs:attribute name="type" type ="xs:string" use="required"/>
</xs:complexType>

<!-- Tags -->
<xs:element name="DataSets
<xs:complexType>
<xs:sequence>
<xs:element name="DataSet" type="DataSet" minOccurs="1" maxOccurs="unbounded

<xs:unique name ="CleUniqueOfDataSet
<xs:selector xpath="."/>
<xs:field xpath="@type"/>
</xs:unique>

</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
[/code]
<br/>



View the full article
 
Back
Top