I have a task to correct the syntax of xml files if they are not well formatted. Currently I am doing this task manually. Is there any way to validate the syntax of XML file, if XML is not well formatted then correct it to well formatted?
Is it possible to validate and correct with Perl script?
Thanks,
XML::LibXML is a validating parser. You can use it to determine if the XML is valid.
Automatically correcting XML is another matter. It’s impossible to automatically fix bad XML without making huge assumptions. For example, there’s no way to know whether
was meant to be
or
or even something else.
XML::LibXML does have an option to automatically fix/ignore some errors. Who knows if it makes the same assumption you do. Use
Use
1for$recoverif you want the parser to be warn when it fixes a problem.Use
2for$recoverif you want the parser to fix problems silently.No matter what you use for
$recover, it will still throw an exception if it encounters an unrecoverable error.