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.

In reply to LibXML: Ignore (or accept) unknown xmlns by timtowtdi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.