Quantcast
Channel: Extracting only the values of xml removing the xml tag - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Extracting only the values of xml removing the xml tag

$
0
0

I have a xml file for example,

<title> hello <name> hi </name> <street> id </street> this is xml file </title>

Here the parent node is title. I am going to extract the text inside the parent node removing the inner tags.

I have tried with the regex. But Is there any way other than using regex like, using some xml based functions to remove the tags. Note: the tag name is not known beforehand.

Hi I have tried this, I used the same xml

use XML::Simple; use Data::Dumper; my $simple = XML::Simple->new(); my $data = $simple->XMLin('XMLRemoval.xml'); my %oldHash = %$data; my %newHash = (); while ( my ($key, $innerRef) = each %oldHash ) {     $newHash{$key} = @$innerRef[1]; } foreach $key ( keys %newHash ) {     print $newHash{$key}; }

And I am getting the error : Can't use string (" id ") as an ARRAY ref while "strict refs"


Viewing all articles
Browse latest Browse all 5

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>