I have the following:
my $string='<entry><name>Bob</name><zip>90210</zip></entry>';
my $parser=XML::LibXML->new();
use HTML::Entities;
my $encodedXml=encode_entities($string,'&\'');
my $doc=$parser->parse_string($encodedXml);
foreach my $text($doc->findnodes("//text()")){
print $text->to_literal,"\n";
}
This prints out ‘Bob’ and ‘90210’;
How do I get the actual node names…I need a way to get all the nodes within my xml tree….ie ‘name’ and ‘zip’
Text nodes don’t have names. Perhaps you want the name of the parent?
I think this will work:
I would use
Note: This later version combines all the text children of the element, so it’s not equivalent if a node has more than one text child. They should be equivalent for you, though.