Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Trouble using XML::XPath::XMLParser::as_string ?

by Plankton (Priest)
on Mar 16, 2011 at 00:48 UTC ( #893467=perlquestion: print w/ replies, xml ) Need Help??
Plankton has asked for the wisdom of the Perl Monks concerning the following question:

I must be missing something about how to use XML::XPath::XMLParser::as_string. Here's what I am doing.

my $xp = XML::XPath->new(xml => $fpdomaininfo ); my $nodeset = $xp->find('//cidr-map'); foreach my $node ($nodeset->get_nodelist) { my $node_name = $node->findvalue ( '@name' ); my $ips_as_string = XML::XPath::XMLParser::as_string($node); $ips_as_string =~ s/ /:/g; # this prints nice list of ipaddresses # 127.0.0.1:198.168.1.1:198.168.1.2 print "<hr><hr>" . __LINE__ . "<br>" . $ips_as_string . "<hr>< +hr>\n";
The above code works fine as far as I can tell. A list if IP addresses is displayed separated by a ':'. Next I do this ...
my @ips = split /:/, $ips_as_string; # Dumper outputs this ... # 589 # $VAR1 = ' print "<hr><hr>" . __LINE__ . "<br>" . Dumper( @ips ) . "<hr>< +hr>\n";
The output is ...
589 $VAR1 = '
... next I do this ...
# this prints crap if XML in it !!! for my $ip ( @ips ) { print "$ip<br>"; }
... where the output include XML tags :/

Is there some subtle point to XML::XPath::XMLParser::as_string I am missing?

Comment on Trouble using XML::XPath::XMLParser::as_string ?
Select or Download Code
Re: Trouble using XML::XPath::XMLParser::as_string ?
by Anonymous Monk on Mar 16, 2011 at 01:29 UTC
Re: Trouble using XML::XPath::XMLParser::as_string ?
by aquarium (Curate) on Mar 16, 2011 at 03:33 UTC
    also..be careful mixing html tags with perl variables inside double quotes. i separate html from variables etc by single quoting all html and join or concatenate to other output. otherwise perl can sometimes misinterpret html tags as greater/smaller comparisons with your perl variables..and closing html tag slashes look like escape chars etc.
    the hardest line to type correctly is: stty erase ^H

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://893467]
Approved by aquarium
Front-paged by aquarium
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-12-27 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls