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

  • Home
  • SEARCH
  • 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 8226789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:53:52+00:00 2026-06-07T15:53:52+00:00

Below is the XML I will be using: <a> <id>ABC</id> <class /> <gender />

  • 0

Below is the XML I will be using:

<a>

<id>ABC</id>

<class />

<gender />

</a>

I want to write a Perl code which search for tag ‘id’ and replace the value “ABC” with “DEF”.

However the nesting of above XML can change. So I want to make a generalized code that search for the tag ‘id’ independently of its exact position.

Till now i am able to get the logic where i can replace the value in ABC but that makes my code static of the position of tag ‘id’.

#!usr/bin/perl
use warnings;
use XML::Simple;
use Spreadsheet::ParseExcel;
use Data::Dumper;
my $FileName = 'sample.xls';
my $xml_file = 'hello.xml';
$par=$ARGV[0];
my $xml = XMLin($xml_file,
    KeepRoot=>1,
    ForceArray=>1,);
$xml->{a}->[0]->{id}='DEF';
XMLout(
    $xml,
    KeepRoot =>1 ,
    NoAttr =>1,
    OutputFile => $xml_file,
        );
    }
  • 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-07T15:53:54+00:00Added an answer on June 7, 2026 at 3:53 pm

    XPath is able to find nodes without needing to know the position in the tree.

    use strictures;
    use XML::LibXML qw();
    my $dom = XML::LibXML->load_xml(string => <<'XML');
    <a>
    <id>ABC</id>
    <class />
    <gender />
    </a>
    XML
    
    for my $id ($dom->findnodes('//id[string()="ABC"]')) {
        $id->removeChildNodes;
        $id->appendText('DEF');
    }
    
    print $dom->toString
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my XML code - <Para> <Desc>....</Desc> <References> <BookRef> <BookName>ABC of HTML</BookName> <Chapter>1</Chapter>
I am using xsd:schema which will be used to generated desired xml, I have
Here is my string. Which will contain XML string Like below var str= <str>rvrv</str>rvrv<q1>vrvv</q1>vrvrv<q2>rtvrvr</q2>;
How to read the below xml file and write its content into a plain
I am working with layout like in below xml code <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have below xml and I am using VBSript to generate it. <?xml version=1.0?>
I have got below xml in my string and I am using c# 2.0
I am trying to write a function that will take an xml object, an
In the XML example below, using a java parser how to keep the content
I am using a code example block in an XML comment as a simple

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.