Hi Monks, I have an XML-file 'imgfile.xml' and I would like to get the values of Hight, Width and Description. I am basically capable of getting all values of all tags, but not when they are formed like in this XML-file:
<?xml version="1.0" encoding="UTF-16" standalone="yes"?> <imgfile IMGFileVersion="1.2.0.2312"> <images> <views> <view type="contacts_view"> <nodes> <node> <properties> <property type="Hight">434</property> <property type="Width">2346</property> <property type="Description">Smile</proper +ty> </properties> </node> <node> <properties> <property type="Hight">1024</property> <property type="Width">768</property> <property type="Description">Background.jp +eg</property> </properties> </node> </nodes> </view> </views> </images> </imgfile>
Script for parsing:
#!/usr/bin/perl use 5.010; use strict; use warnings; use XML::LibXML; #my $FILENAME = ('imgfile.xml'); my $parser = XML::LibXML->new; my $dom = XML::LibXML->load_xml( location => 'imgfile.xml' ); print 'XML Version is: ', $dom->version, "\n"; print 'Document encoding is: ', $dom->encoding, "\n"; foreach my $image ($dom->findnodes('imgfile/images/views/view/nodes/no +de/properties')) { say 'Description: ', $image->findvalue('./Description'); } exit(0);
I am trying to parse it with the perlscript above, but as you may probably understand, it only returns: (For the example I only try to get the Description-value)
XML Version is: 1.0 Document encoding is: UTF-16 Description: Description:
How can I get the value of the Description property?
The great mistake is to anticipate the outcome of the engagement; Let nature take its course, and your tools will strike at the right moment.

In reply to LibXML: Can't get value of attribute using DOM 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.