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 8246425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:30:08+00:00 2026-06-07T22:30:08+00:00

How can I return the entire xml tag using xml::twig and save it to

  • 0

How can I return the entire xml tag using xml::twig and save it to array:

for example :

my @array=();
my $twig = XML::Twig->new(
twig_handlers => {
'data'=> sub {push @array, $_->xml_string;}

});

This code return all the nested tags but without the tag itself and its properties is there an option to return the entire tag using xml::twig and save it to varaible ?

  • 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-07T22:30:11+00:00Added an answer on June 7, 2026 at 10:30 pm

    Use XML::Twigs method sprint instead of xml_string. The docs say that:

    xml_string @optional_options

    Equivalent to $elt->sprint( 1), returns the string for the entire element, excluding the element's tags (but nested element tags are present)
    

    A search for that sprint function yields:

    sprint

    Return the text of the whole document associated with the twig. To be used only AFTER the parse.
    

    Thus, you can do the following:

    use strict;
    use warnings;
    use Data::Dumper;
    use XML::Twig;
    
    my @array=();
    my $twig = XML::Twig->new(
    twig_handlers => {
      'data'=> sub {push @array, $_->sprint;}
    });
    
    $twig->parse(qq~
      <xml>
            <data id="foo">
          <deep>
                <deeper>the deepest</deeper>
          </deep>
        </data>
      </xml>
    ~);
    
    print Dumper \@array;
    

    Which prints:

    $VAR1 = [
              '<data id="foo"><deep><deeper>the deepest</deeper></deep></data>'
            ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JPQL queries can return custom result objects with the NEW operator: SELECT NEW myPackage.MyVO(e.fieldX,
In c# you can return an integer to the underlying caller using Environment.Exit(n) (which
I have a WCF service that can return large amount of data depending on
The question(s): Can a XPath 1.0 expression return only the names of xml nodes
Using PHP, how do I get an entire subset of nodes from an XML
I'm receiving data from web-services in XML and I'm using that data via objects,
How can return a subset of a FormCollection with key/values in tact for those
How can return a variable from a thead (I have the threads handle too).
I know that I can return the index of a particular character of a
I have an Ajax request that can return more than one valid value, so

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.