huiling has asked for the wisdom of the Perl Monks concerning the following question:
I get#!/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"; } }
as output how do i get rid of the lines? (i.e. i want "description/assertion command", etc) my file looks sth like this:description/assertion command etc,
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. =)<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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: why spaces! XML::DOM
by pjotrik (Friar) on Jul 10, 2008 at 09:48 UTC | |
|
Re: why spaces! XML::DOM
by Lawliet (Curate) on Jul 10, 2008 at 09:57 UTC | |
by pjotrik (Friar) on Jul 10, 2008 at 10:16 UTC | |
by Lawliet (Curate) on Jul 10, 2008 at 10:31 UTC |