perl - "Not well-formed" error from XML::Simple -


i'm trying parse xml contains namespace xml::simple throwing error.

not well-formed (invalid token) @ line 3, column 53, byte 63 
use data::dumper; use xml::simple;  $string = q( <result> <something id="207" xlink:href="http://someurl.com&op=yeah">something 207</something> </result> );  print dumper(xmlin($string)); 

is there way can work xml::simple? or have use different xml parsing library?

please take note of warning in documentation xml::simple, reads follows:

the use of module in new code discouraged. other modules available provide more straightforward , consistent interfaces. in particular, xml::libxml highly recommended , xml::twig excellent alternative.

xml documents may not contain ampersands & or angle brackets < > outside cdata sections. within ordinary (pdata) data sections , attribute values need replaced entities &amp; &lt; , &gt; respectively

your program correct , data malformed. character 53 of line 3 here

<something id="207" xlink:href="http://someurl.com&op=yeah">something 207</something>                                                     ^                                                 column 53 

so reporting p (because &op isn't start of known entity) , problem nothing namespaces

my version of xml::simple (currently recent version 2.22) gives more explicit message

entity: line 3: parser error : entityref: expecting ';' <something id="207" xlink:href="http://someurl.com&op=yeah">something 207</somet                                                      ^ 

you can fix things replacing ampersand entity, this

use strict; use warnings 'all';  use data::dump; use xml::simple;  $string = <<end_xml; <result>   <something id="207" xlink:href="http://someurl.com&amp;op=yeah">something 207</something> </result> end_xml  dd xmlin($string); 

output

{   => {     "content" => "something 207",     "id" => 207,     "xlink:href" => "http://someurl.com&op=yeah",   }, } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -