I saw a related question when i was searching, but mine might be a bit different? i just started using perl 3 days ago, and its the second programming language i learnt. (first was matlab!) in any case, could someone please teach me how i can get the text i want? thanks!! here's my code:
#!/usr/bin/perl -w use XML::DOM; use strict; my ($file, @rubbish) = @ARGV; if ($#ARGV > 0 ){ die; } my $parser = new XML::DOM::Parser; my $doc = $parser->parsefile($file); my $root = $doc->getDocumentElement(); print "$root\n"; scanner($root); sub scanner { my ($rt) = @_; my $i=0; foreach my $track ($rt->getElementsByTagName('track')){ foreach my $ping ( $track->getChildNodes()){ foreach my $nde ( $ping->getChildNodes()) { #my $nde = $nee->getNextSibling; if ($nde->getNodeType == ELEMENT_NODE) { #$log->info( $i.$nde->getTagName()); print $i++, " ELEMENT ", $nde->getNodeValue(), "\n"; } scanner( $nde ); } } } } } my file looks sth like this: <track name="linguist.segments" type="primary"> - <el index="0" start="0.44" end="0.56"> <attribute name="semantics">abstract</attribute> <attribute name="type">description/assertion</attribute> </el> - <el index="1" start="0.56" end="0.76"> <attribute name="semantics">abstract</attribute> <attribute name="type">command</attribute> </el> </track>
i want to be able to extract 'description/assertion' and 'command' from my code. Thanks so much! Ok, I figured out what is wrong. The text node is a child node of the element node lol.

In reply to XML::DOM help by huiling

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.