I am trying to validate an XML against schema using LibXML::Schema Validator CPAN module. In that same script am using XML::DOM CPAN module to parse the XML. I want my script to take XML file validate it against XSD and parse it.
When I try to run the script, after validating against xsd it exits and does not parse XML. I want it parse the XML file if it is valid and generate DOM structure. I would really appreciate if someone could share some insights on it.
#usr/bin/perl -w
use XML::LibXML;
my $schema = XML::LibXML::Schema->new(location =>'export.xsd');
my $parser = XML::LibXML->new;
my $xml = 'Export.xml';
my $doc = $parser->parse_file($xml);
eval { $schema->validate( $doc ) };
print $@ if $@;
print "$xml is valid\n";
use XML::DOM;
#use strict;
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ("Export.xml");
my $productOfferingnodes = $doc->getElementsByTagName("productOfferings")->item(0);
my @productOffering = $productOfferingnodes->getChildNodes();
{
foreach my $productOffering(@productOffering)
{
if ($productOffering->getNodeType == ELEMENT_NODE)
{
print $productOffering->getNodeName;
}
}
}
Error Message:
Schemas parser error : Failed to parse the XML resource 'export.xsd'.