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>
In reply to why spaces! XML::DOM by huiling
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |