Hi gurus,

I wanted to validate  xml file against specified  xsd file.

Is there any perl module which does this?


Below are the details:

XML file
-----------

<?xml version="1.0" encoding="UTF-8"?>
<ws:getCategories xmlns:ws="http://services.ws.faculte.com";
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 xsi:ws="Webservices.xsd">
 <networkID>1</networkID>
</ws:getCategories>


XSDFile
---------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xsd="http://services.ws.faculte.com/xsd";
 xmlns:ns0="http://wsbean.ws.faculte.com/xsd";
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 attributeFormDefault="qualified" elementFormDefault="qualified"
 targetNamespace="http://services.ws.faculte.com/xsd";>
 <xs:annotation>
  <xs:documentation>
   This lists the input requests and output responses for the
   following web services: getCategories,getTopics
  </xs:documentation>
 </xs:annotation>
 <xs:import schemaLocation="Topics.xsd"
  namespace="http://wsbean.ws.faculte.com/xsd";>
 </xs:import>
 <xs:element name="getCategories">
  <xs:complexType>
   <xs:sequence>
    <xs:element minOccurs="1" maxOccurs="1" name="networkId"
     type="xs:long" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element name="getCategoriesResponse">
  <xs:complexType>
   <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0"
     name="return" nillable="true" type="ns0:Category" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element name="getTopics">
  <xs:complexType>
   <xs:sequence>
    <xs:element minOccurs="1" maxOccurs="1"
     name="topicRequest" nillable="true" type="ns0:TopicRequest" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element name="getTopicsResponse">
  <xs:complexType>
   <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0"
     name="return" nillable="true" type="ns0:Topic" />
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

---------------

I have used the below perl script

----------------------------------------------------


use strict;
use warnings;
use XML::SAX::ParserFactory;
use XML::Validator::Schema;
my $xsd_file = 'Webservices.xsd';
my $xml_file = 'RequestTopics.xml';
my $validator = XML::Validator::Schema->new(file => $xsd_file);
my $parser = XML::SAX::ParserFactory->parser(Handler => $validator);
eval { $parser->parse_uri($xml_file) };
if ($@) {
    print "File failed validation: $@"
} else {
    print "proceed with parsing XML\n";
}
-------------------------------------------------------------------------------

But i got the below error even though the xml file is as per xsd file
-----------------------------------------------------------------------------------------

could not find ParserDetails.ini in C:/Perl/site/lib/XML/SAX
elementFormDefault in <schema> must be 'unqualified', 'qualified' is not
supported.
--------------------------------------------------------------------------------------------------------------------


Can any body help me in validating xml file wtih above specified xsd file.

Thanks in Advance,
Siva

Reply via email to