#!/usr/bin/perl -w use XML::DOM; use strict; my ($file, @rubbish) = @ARGV; if ($#ARGV > 0 ){ die; } else { my $parser = new XML::DOM::Parser; my $doc = $parser->parsefile($file); my $root = $doc->getDocumentElement(); scanner($root); sub scanner { my ($rt) = @_; my @list; foreach my $track ($rt->getElementsByTagName('track')) { foreach my $el ( $track->getChildNodes()) { foreach my $attr ( $el->getChildNodes()) { if ($attr->getNodeType == ELEMENT_NODE) { if ($attr-> getAttribute('name') eq "type"){ foreach my $type ($attr->getChildNodes()){ push (@list, $type->getData()); } } } } } }print "@list"; } }
I get
description/assertion command etc,
as output how do i get rid of the lines? (i.e. i want "description/assertion command", etc) 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>
thanks so much! hi, thanks to all who replied, i opened my source code and realised it's different from what it shows on the xml editor.
<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 used $temp =~ s/\s//g; in the end, and it works now. i feel like such an idiot now. =)

In reply to why spaces! XML::DOM 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.