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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:53:57+00:00 2026-06-16T08:53:57+00:00

I new to xml twig, how can I add space between two elements in

  • 0

I new to xml twig, how can I add space between two elements in xml-twig?

Input:

<xml>
<fig id="fig6_4">
<label><xref ref-type="page" id="page_54"/>[Figure 4]</label>
<caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>

Script:

$xml_twig_content = XML::Twig->new(
                                   twig_handlers => {
                                   'fig' => \&figure,
},
                                  );
$xml_twig_content->parsefile('sample.xml');

sub figure{
my ($xml_twig_content, $figure) = @_;
my @figchild = $figure->children;
foreach my $chid (@figchild){
if ($chid->name =~ /label/){
        my $t = $chid->text;
        $chid->set_inner_xml($t . ' ');
        $chid->erase;
}

output:

<xml>
<fig id="fig6_4">
[Figure 4] <caption>The Klein Sexual Orientation Grid</caption>
</fig>
</xml>

i need:

<xml>
    <fig id="fig6_4">
    <xref ref-type="page" id="page_54"/>[Figure 4] <caption>The Klein Sexual Orientation Grid</caption>
    </fig>
    </xml>

how can i inset space between two elements…..

  • 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-16T08:53:58+00:00Added an answer on June 16, 2026 at 8:53 am

    I would use a handler on fig/label, since that’s the only element that needs to be modified. The code in the handler then needs to suffix the element with whitespace, then erase the tag:

    XML::Twig->new( twig_handlers => { 'fig/label' => sub { $_->suffix( ' ')->erase; }});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to add the elements from the new XML to the old XML
I'm new to querying XML datatype in SQL Server 2005. Anyone can help me
I'm relatively new to Perl, writing some XML parsing scripts. I have done two
I can't seem to figure out how to create a new XML file in
how we can create new xml file by C# in the following situation: its
I am still new with using XML::Twig . From the main program I look
How can I return the entire xml tag using xml::twig and save it to
Can we create a new xml file using the jsp coding anyone help me
I'm using Expression Blend 3 I click on add live datasource, add new xml
I am new XML-Twig... I want split para tag.... XML File: <xml> <p class=indent>text

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.