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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:16:54+00:00 2026-06-14T23:16:54+00:00

I want to parse a simple string using XML::Parser. This works fine. But I

  • 0

I want to parse a simple string using XML::Parser. This works fine. But I do not know how to access the result.

#!/usr/bin/perl

use Data::Dumper;
use XML::Parser;

my $parser = XML::Parser->new( Style => 'Tree' );
my $tree   = $parser->parse( '<xml type="test" Id="ca19cfd5" result="1 test 2 test 3" elapsed="9" Size="12345" />' );

print Dumper( $tree );

shows me

$VAR1 = [
'xml',
[
{
'Size' => '12345',
'Id' => 'ca19cfd5',
'type' => 'test',
'elapsed' => '9',
'result' => '1 test 2 test 3'
 }
 ]
 ];

So it perfectly could parse my string. But how do I access these fields? Something like “my $result = $tree…”

The given xml string will always have the same syntax like shown above. Only the content differs.

Tnx in advance,
Enkidu

  • 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-14T23:16:55+00:00Added an answer on June 14, 2026 at 11:16 pm

    The attributes you are looking for are in $tree->[1]->[0]

    my $atts= $tree->[1]->[0];
    

    then

    print "size: $atts->{Size}\n";
    

    That said XML::Parser is not the easiest module to use, it’s a bit too low-level. XML::Twig or XML::LibXML will give you what you want more easily.

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

Sidebar

Related Questions

I want to parse the xml file with dynamic content using DOM parser in
I want to parse a xml file using xquery in Ruby, I found this
I am writing a simple XML file parser using LINQ to XML. I want
I want to parse the result of a specific URL using Simple Ajax for
I am new to jquery. I am trying to parse xml string using jquery.
Possible Duplicate: Creating a simple XML file using python I want to write a
I want to parse a search string similar to that provided by Gmail using
I want to parse an XML file using Perl . I was able to
It's very simple task, but I struggle for hours. I have parse xml from
Not new to Java; but relatively new to XML-parsing. I know a tiny bit

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.