views:

72

answers:

3

I know there are quite some threads talking about validating XML file against its XML schema, such as : validate-xml-using-libxml and xml-schema-validation-with-relaxng

So if there is a simple Perl module on CPAN that can test this with minimal code, then that would be very fantastic to know.

+4  A: 

You can simply use XML::Parser.

Note that your question title refers to being well-formatted (well-formed?) whereas the body refers to validation. If you want to validate (against a schema) check out XML::Validator::Schema.

Brian Agnew
@Brian Agnew: Thanks for this quick answer and sorry about the wrong term, yeah, you are right, I mean well-formed not well-formatted :)
Michael Mao
+2  A: 

I'd use Test::XML. It gives you methods is_xml, is_well_formed_xml.

jira
Test::XML is for writing test scripts ala Test::More and Test::Builder, and as such isn't very useful outside of a test script. But you can examine its source code to see how to use XML::Parser to check if your XML is well-formed.
cjm
+1  A: 

There's XML::Compile, but it's not easy until you learn to use the module.

brian d foy