Perl's XML::SemanticDiff - Getting the attribute value when there is a difference -



Perl's XML::SemanticDiff - Getting the attribute value when there is a difference -

apologies in advance question, i'm new perl.

i'm comparing 2 xml files using xml::semanticdiff, own custom handler implemented. part works, when have 2 xml elements beingness compared like:

<tag attribute="value">

and

<tag attribute=" value ">

i want not count difference. xml::semanticdiff calls element_value method. how value of new , old attribute value can trim out whitespace , compare them? documentation mentions can done keepdata parameter (which have added), beingness new perl don't understand how info when i'm in element_value method.

thanks in advance, thomas

if want enclosing spacing ignored in xml attributes, suggest remove before trying compare documents.

the next uses xml::libxml remove spacing embedded xml document, adapt xml file well.

use strict; utilize warnings; utilize xml::libxml; $dom = xml::libxml->load_xml(io => \*data); $attr ($dom->findnodes('//@*')) { $string = $attr->getvalue(); if ($string =~ s/\a\s+|\s+\z//g) { $attr->setvalue($string); } } print $dom->tostring(); __data__ <root> <tag attribute=" value "/> </root>

outputs:

<?xml version="1.0"?> <root> <tag attribute="value"/> </root>

xml perl whitespace

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -