I have an xml file with one of its child elements as:
<datacolumn name="Latitude" units="Degrees"> <item value="40.9408"/> <item value="40.7698"/> <item value="40.5629"/> <item value="40.3019"/> <item value="39.9689"/> <item value="40.0589"/> <item value="39.9509"/> <item value="39.9149"/> <item value="39.4199"/> <item value="39.204"/> <item value="39.078"/> <item value="38.88"/> <item value="38.772"/> <item value="38.754"/> <item value="38.502"/> <item value="38.403"/> <item value="38.331"/> <item value="38.151"/> <item value="38.0251"/> <item value="37.9981"/> <item value="37.8901"/> <item value="37.8631"/> <item value="37.7461"/> <item value="37.4581"/> <item value="37.4491"/> <item value="37.2601"/> <item value="37.2691"/> <item value="37.1791"/> <item value="37.1971"/> <item value="37.0261"/> <item value="36.9541"/> <item value="36.9271"/> <item value="36.5042"/> <item value="36.5132"/> </datacolumn>
I want to extract this data using XML::LibXML but am not sure how. So far I have:
#!/usr/bin/perl -w use strict; use XML::LibXML; my $parser = XML::LibXML->new; my $xmlfile = "20060402-201025.xml"; my $doc = $parser->parse_file($xmlfile); my $element = $doc->getDocumentElement; my @nodes = $element->getElementsByTagName('data'); foreach my $kid1(@nodes) { my $elname2 = $kid1 -> getName(); print $elname2,"\n"; my $lon = $kid1->getAttribute('Longitude'); print $lon,"\n"; }
This doesnt work since the datacolumn is not an attribute. I'm not sure what it is. Any ideas?

In reply to XML::LibXML extracting datacolumn by deadpickle

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.