Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

by Plankton (Vicar)
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 # 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?

Replies are listed 'Best First'.
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 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://893467]
Approved by aquarium
Front-paged by aquarium
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-01-17 20:55 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (206 votes). Check out past polls.