http://qs321.pair.com?node_id=593243

DigitalKitty has asked for the wisdom of the Perl Monks concerning the following question:

Hi all.

I'm currently in the process of teaching myself how to use XPath and Perl to parse XML documents (most notably, the chatterbox feed). After reading the documentation, I felt compelled to inquire about removing the attribute name in the output (please see below):

<?xml version="1.0" encoding="ISO-8859-1"?> <CHATTER> <INFO site="http://perlmonks.org/" sitename="PerlMonks" ticker_id="158 +34" gentimeGMT="2007-01-05 23:29:59" xmlstyle="old" xmlmaker="XML::Fling 1.001" count="3" lastid= +"419432"> Rendered by the Chatterbox XML Ticker</INFO> <message user_id="22609" author="tye" time="20070105182057"> is "this proxy" that you mentioned relatively new?</message> <message user_id="170442" author="jdporter" time="20070105182124"> is that a problem?</message> <message user_id="170442" author="jdporter" time="20070105182217"> oh, sorry. yes, looks like [merlyn|he] is having a problem.</message> </CHATTER>


By using the short program provided by the module's author and what I had already gleaned from various online tutorials, I was able to display the value of each 'author' attribute:

#!/usr/bin/perl use warnings; use strict; use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => 'pm.xml'); my $nodeset = $xp->find('//@author'); # find all authors foreach my $node ($nodeset->get_nodelist) { print XML::XPath::XMLParser::as_string($node), "\n\n"; }


Output:

C:\Perl\bin>perl test.pl author="tye" author="jdporter" author="jdporter" C:\Perl\bin>


Is there a method I'm unaware of that will display only the value(s) and omit the atttribute 'name='(?)

Thanks,
~Katie