Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:31:20+00:00 2026-06-13T11:31:20+00:00

I have a xml file for example, <title> hello <name> hi </name> <street> id

  • 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”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:31:21+00:00Added an answer on June 13, 2026 at 11:31 am

    Based on your requirement, you can try this.
    I have used the file provided by you in example.

    we are here defining the root key contents in XML(or renaming it), you need to choose a key which will not be in your XML( i have choose root-contents).

    #!/usr/bin/perl
    use strict;
    use XML::Simple;
    use Data::Dumper;
    my $key;
    my $simple = XML::Simple->new();
    my $data = $simple->XMLin('XMLRemoval.xml', 'ContentKey' => 'root-contents');
    print Dumper $data;
    my $val = $data->{'root-contents'};
    if(ref($val) =~ /Array/i)
    {
        foreach (@$val)
        {
            print "$_\n";
        }
    }
    else
    {
        print "$val\n";
    }
    

    Please go though the XML::Simple documentation, there are lot of options to tweak per your requirement.

    I will leave the debug part to you for your code to check what was the error and how can solve it(which is explanatory itself) :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML like this: <article> <title>Article 1 title</title> <text>Lorem ipsum...</text> <image>http://example.com/img_01.jpg</image> </article> <article>
This is example of my XML file <head> <cat>some title here... <info>some info here
I have this PHP file: <?php header('Content-type: text/xml; charset=UTF-8'); ?><?xml version=1.0 encoding=UTF-8 ?> <Module>
I have an XML-like file that has lines that look like this: <siteMapNode title=Our
For example I have the following XML file: <?xml version=1.0 encoding=ISO-8859-1?> <bookstore> <book> <title
I have the following XML file: <phonebook> <departments> <department id=1 parent= title=Rabit Hole address=
Hello I have an XML code like this: <article> <title><![CDATA[IEEE Transactions on]]></title> <articleinfo> <articleseqnum>13</articleseqnum>
Hoi, for example, i have a xml file : <bookstore> <book category=COOKING> <title lang=en>Everyday
say, i have such xml file: <?xml version=1.0?> <catalog> <title>My book catalog</title> <link>http://example.com/catalog</link> <book
I have the following in an XML file: <entry> ... <link href=http://www.example.com/somelink /> ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.