timtowtdi has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I would like to parse an xml-file with an xmlns-declaration I don't know of and doesn't seem to exist. The XML is parsed fine without this xmlns-declaration. If I let it in, no description, height or width is returned.

Is there a way to ignore this xmlns-decleration? (So, the parsing works as without this declaration)

Perlscript (thanks to choroba):
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => 'imgfile.xml'); say 'XML Version is: ', $dom->version; say 'Document encoding is: ', $dom->encoding; for my $image ( $dom->findnodes('/imgfile/images/views/view/nodes/node/properties' +) ) { for my $property (qw( Description Height Width )) { say "$property: ", $image->findvalue("property[\@type='$proper +ty']"); } }

XML-File:

<?xml version="1.0" encoding="UTF-16" standalone="yes"?> <imgfile IMGFileVersion="1.2.0.2312" xmlns="http://foobar.com/version/ +2.0"> <images> <views> <view type="contacts_view"> <nodes> <node> <properties id="guid1"> <property type="Height">434</property> <property type="Width">2346</property> <property type="Description">Smile</proper +ty> </properties> </node> <node> <properties id="guid2"> <property type="Height">1024</property> <property type="Width">768</property> <property type="Description">Background.jp +eg</property> </properties> </node> </nodes> </view> </views> </images> </imgfile>
Changing the second line from: <imgfile IMGFileVersion="1.2.0.2312" xmlns="http://foobar.com/version/2.0">to<imgfile IMGFileVersion="1.2.0.2312"> solves the issue.

Replies are listed 'Best First'.
Re: LibXML: Ignore (or accept) unknown xmlns
by Corion (Patriarch) on Dec 28, 2016 at 15:22 UTC