Validating xml file against xsd



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


Relevant Pages

  • Re: Deserialize from SelectSingleNode
    ... I thought it was talking about the namespace for XXX, ... my class name was generated from an XSD file for the ... XML file I'm working with. ... The class name has the form AAABBBCCC, ...
    (microsoft.public.dotnet.xml)
  • RE: ReadXML and data types
    ... If I want to put the schema in a separate XSD file, ... with my XML file for ReadXml to use? ... > Kevin Yu ...
    (microsoft.public.dotnet.xml)
  • RE: SQLXMLBulkLoad and Keys
    ... and this hierarchy is not represented in the schema. ... For me it is easier to see it with all the indentations: ... > I've created a DTS package to bulk import an XML file into SQL Server ... > in the XSD file having something to do with the Sales_Price_Info key ...
    (microsoft.public.sqlserver.xml)
  • Re: How to associate XML with XSD
    ... "MyDefaultNamespace" is usually a string that looks like a ... that my XML file has an associated XSD file? ... the schema of app.config files even though the text of the app.config file ...
    (microsoft.public.dotnet.xml)
  • Xerces-C++ Schema validation
    ... I'm looking for a way of validating/parsing the xsd file (schema), ... only been able of validating the xml file with the corresponding ... schema, but what i want is only validate the xsd file, to check if the ...
    (comp.text.xml)