8

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

1

2 Answers 2

5

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

perl -MCPAN -e 'install XML::Validator::Schema'
Sign up to request clarification or add additional context in comments.

18 Comments

@Brian - thanks for your quick response, I am not able to find this module on ActivePerl. Any good alternative on ActivePerl? I am hoping to find a module that is available and runs on both Windows and Linux.
If you have to use perl on windows I suggest you use strawberry perl instead. ** strawberryperl.com ** It's much better than ActivePerl (when it comes to package coverage (and other things too)) I supplies a proper CPAN chell to install and compile a lot more packages.
I don't know, I'm afraid. I would hope ActivePerl would support CPAN, but perhaps not.
@Nifle - Unfortunately, I don't have a choice to switch over to strawberryperl. Thanks for bringing it up anyway.
ActivePerl does "support CPAN", and this module (and thousands of others). It's in the list at ppm4.activestate.com/idx/X...Z.html
|
2

XML::LibXML::Schema has a validate method.

See also my answer to Why does my XSD file fail to parse with XML::LibXML?.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.