How can I validate XML with XSD in Perl?

perl, xml, xsd

Solution

I think you need XML::Validator::Schema from CPAN. Here's the README, and to install:

perl -MCPAN -e 'install XML::Validator::Schema'

Problem

This may be a simple question for most Perl programmers, I have only used Perl for two weeks so far and am very unfamiliar with the Perl packages. I have a simple XSD file as below: ``` <?xml version="1.0" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="elementname"> <xsd:complexType> <xsd:sequence> <xsd:element name="field1" type="xsd:integer" minOccurs="0" maxOccurs="1"/> <xsd:element name="field2" type="xsd:string" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> ``` I would love to validate an XML file with the above XSD to ensure this is a valid XML. What Perl module should I use? I prefer a module that is available both on ActivePerl and Perl on *nix. Would be very helpful to post some code snippets. Thanks

Original source

Related problems