Thursday, 15 January 2015

check and correct xml syntax in perl -



check and correct xml syntax in perl -

i have task right syntax of xml files if not formatted. doing task manually. there way validate syntax of xml file, if xml not formatted right formatted?

is possible validate , right perl script?

thanks,

xml::libxml validating parser. can utilize determine if xml valid.

use xml::libxml qw( ); $parser = xml::libxml->new(); if (eval { $parser->parse_file($qfn) }) { print "ok\n"; } else { print "error:\n$@"; }

automatically correcting xml matter. it's impossible automatically prepare bad xml without making huge assumptions. example, there's no way know whether

<foo>/bar<baz/</foo>

was meant be

<foo>/bar&lt;baz/</foo>

or

<foo>/bar<baz/></foo>

or else.

xml::libxml have alternative automatically fix/ignore errors. knows if makes same assumption do. use

use xml::libxml qw( ); $parser = xml::libxml->new( recover => $recover ); $doc = $parser->parse_file($in_qfn); $doc->tofile($out_qfn);

use 1 $recover if want parser warn when fixes problem. utilize 2 $recover if want parser prepare problems silently. no matter utilize $recover, still throw exception if encounters unrecoverable error.

xml perl perl-module

No comments:

Post a Comment