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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:30:34+00:00 2026-05-26T01:30:34+00:00

Can someone show me how to parse out specific information from an xml file?

  • 0

Can someone show me how to parse out specific information from an xml file? Am I suppose to use a regex?

I am using XML::Simple to view my test.xml file.

For example, I want to search for the string test-out-00000, if it exists then give me/print the size = 135860644

Data:

$VAR1 = {
          'recursive' => 'no',
          'version' => '0.20.202.1.1101050227',
          'time' => '2011-09-30T02:49:39+0000',
          'filter' => '.*',
          'file' => {
                    'owner' => 'test_act',
                    'replication' => '3',
                    'blocksize' => '134217728',
                    'permission' => '-rw-------',
                    'path' => '/source/feeds/customer/test/test-out-00000',
                    'modified' => '2011-09-30T02:48:41+0000',
                    'size' => '135860644',
                    'group' => '',
                    'accesstime' => '2011-09-30T02:48:41+0000'
                  },
          'path' => '/source/customer/test',
          'directory' => {
                         'owner' => 'test_act',
                         'group' => '',
                         'permission' => 'drwx------',
                         'path' => '/source/feeds/customer/test',
                         'accesstime' => '1970-01-01T00:00:00+0000',
                         'modified' => '2011-09-30T02:48:41+0000'
                       },
          'exclude' => ''
        };
recursive:no
version:0.20.202.1.1101050227
time:2011-09-30T02:49:39+0000
filter:.*
file:HASH(0x84c841c)
path:/source/customer/test
directory:HASH(0x84c7648)
exclude:

Working perl script:

use strict;
use warnings;
use XML::Simple;
use Data::Dumper;

my $xml = $ARGV [0]; 
my $data = XMLin($xml);
print Dumper( $data );

foreach my $attributes (keys %{$data}){
  print"$attributes:${$data}{$attributes}\n";
}

XML file test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<listing time="2011-09-30T02:49:39+0000" recursive="no" path="/source/customer/test" exclude="" filter=".*" version="0.20.202.1.1101050227">
<directory path="/source/feeds/customer/test" modified="2011-09-30T02:48:41+0000" accesstime="1970-01-01T00:00:00+0000" permission="drwx------" owner="test_act" group=""/>
<file path="/source/feeds/customer/test/test-out-00000" modified="2011-09-30T02:48:41+0000" accesstime="2011-09-30T02:48:41+0000" size="135860644" replication="3" blocksize="134217728" permission="-rw-------" owner="test_act" group=""/>
</listing>
  • 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-05-26T01:30:35+00:00Added an answer on May 26, 2026 at 1:30 am

    I’m assuming you’re always looking for the text string in the filename? If so, this is one way of doing it:

    use strict;
    use warnings;
    use XML::Simple;
    
    my $xml = $ARGV [0]; 
    my $data = XMLin($xml);
    
    my $size = 0;    
    
    if (exists $data->{file}->{path} and $data->{file}->{path} =~ /test-out-00000/) {
        $size = $data->{file}->{size};
    }
    

    If your data follows this format you could also use XML::LibXML to just grab the values using an XPATH expression.

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

Sidebar

Related Questions

Can someone show me how to use the System.Numerics.BigInteger datatype? I tried using this
Can someone show me a regex to select #OnlinePopup_AFE53E2CACBF4D8196E6360D4DDB6B70 its okay to assume #OnlinePopup
I am creating menus in WPF programatically using vb.net. Can someone show me how
Can someone show me the simplest way of perform a parametrized SQL query using
Can someone show me a simple way I can test if someone's cookies are
I am trying to use xml.etree.ElementTree to parse responses from eBay finding API, findItemsByProduct.
Can someone show me how to implement a recursive lambda expression to traverse a
Can someone show me how to get the top & left position of a
Can someone show me how to fix the width of a column in a
Can someone show me the MySQL equivalent of the following statement (which works in

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.