Hi,
I have a xml file and a xsd file(xml schema file). Here using unix script i wanted to validate the xml file by referring to xsd file. The validation is in terms of Datatype,Field length and null values. If the data present in the xml file is not matching in terms of datatype,field length and null values which are specified in the xsd file , then the bad records should go into badfile and good validated records into goodfile.
XML and XSD files are given below :
XSD file : bookSchema.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="generic" elementFormDefault="qualified" targetNamespace="generic">
<xsd:element name="bookstore" type="bookstoreType"/>
<xsd:complexType name="bookstoreType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="book" type="bookType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="author" type="authorName"/>
<xsd:element name="price" type="xsd:integer"/>
</xsd:sequence>
<xsd:attribute name="genre" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="authorName">
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string"/>
<xsd:element name="last-name" type="xsd:string"/>
<xsd:element name="age" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
XML file : books.xml
<?xml version="1.0"?>
<bookstore xmlns="generic">
<book genre="autobiography">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Ben</first-name>
<last-name>Franklin</last-name>
<age>35</age>
</author>
<price>89</price>
</book>
<book genre="fiction">
<title>Harry Potter</title>
<author>
<first-name>Joseph</first-name>
<last-name>Melville</last-name>
<age>abc</age>
</author>
<price>300</price>
</book>
<book genre="novel">
<title>2 States</title>
<author>
<first-name>Chethan11</first-name>
<last-name>Bhagath</last-name>
<age>35</age>
</author>
<price>150</price>
</book>
<book genre="autobiography">
<title>Wings of Fire</title>
<author>
<first-name>Abdul</first-name>
<last-name>Kalam</last-name>
<age>58a</age>
</author>
<price>200</price>
</book>
<book genre="autobiography">
<title>Adventures of Tintin</title>
<author>
<first-name>George</first-name>
<last-name>Zumby</last-name>
<age>44</age>
</author>
<price>200</price>
</book>
<book genre="novel">
<title>Adventures</title>
<author>
<first-name>44444</first-name>
<last-name>Zumby</last-name>
<age>44</age>
</author>
<price>205</price>
</book>
</bookstore>
After validation expected result is
Goodfile:
<?xml version="1.0"?>
<bookstore xmlns="generic">
<book genre="autobiography">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Ben</first-name>
<last-name>Franklin</last-name>
<age>35</age>
</author>
<price>89</price>
</book>
<book genre="novel">
<title>2 States</title>
<author>
<first-name>Chethan11</first-name>
<last-name>Bhagath</last-name>
<age>35</age>
</author>
<price>150</price>
</book>
<book genre="autobiography 123">
<title>Adventures of Tintin</title>
<author>
<first-name>George</first-name>
<last-name>Zumby</last-name>
<age>44</age>
</author>
<price>200</price>
</book>
</bookstore>
Badfile :
<?xml version="1.0"?>
<bookstore xmlns="generic">
<book genre="fiction">
<title>Harry Potter</title>
<author>
<first-name>Joseph</first-name>
<last-name>Melville</last-name>
<age>abc</age>
</author>
<price>300</price>
</book>
<book genre="autobiography">
<title>Wings of Fire</title>
<author>
<first-name>Abdul</first-name>
<last-name>Kalam</last-name>
<age>58a</age>
</author>
<price>200</price>
</book>
<book genre="novel">
<title>Adventures</title>
<author>
<first-name>44444</first-name>
<last-name>Zumby</last-name>
<age>44</age>
</author>
<price>205</price>
</book>
</bookstore>
How this can be done using unix script ?
Regards,
Shree