Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How can i validate xml file?

by grantm (Parson)
on Feb 23, 2006 at 23:38 UTC ( [id://532422]=note: print w/replies, xml ) Need Help??


in reply to How can i validate xml file?

You seem to be wanting to check that an XML document is 'well formed'. Here's a Perl one-liner that will do that:

perl -MXML::Parser -e "XML::Parser->new( ErrorContext => 3 )->parsefil +e(shift)" your_file.xml

If you were incorporating it into a larger script, then you'd want to wrap it in eval { ... } and check the contents of $@ afterwards.

One trap with using XML::Simple for well-formedness checks is that the SAX parser included in the latest release of XML::LibXML does not die on all parse errors.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://532422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found