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:
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.<?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>
In reply to LibXML: Ignore (or accept) unknown xmlns by timtowtdi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |