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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:28:53+00:00 2026-05-16T01:28:53+00:00

I am using XML::Simple to parse a XML file. The output is a hash.(using

  • 0

I am using XML::Simple to parse a XML file. The output is a hash.(using Data::Dumper)

Sample code , XML file are given below with output.

Perl code:

use XML::Simple;
use Data::Dumper;

$xml = new XML::Simple;

$data = $xml->XMLin("spam.xml");

print Dumper($data);

XML file contents (input to parser)::

<Attach_request>
    <Protocol_discriminator>
        <name> Protocol_discriminator </name>
        <attribute> Mandatory </attribute>
        <type> nibble </type>
        <value> 7 </value>
        <min> 0 </min>
        <max> F </max>
    </Protocol_discriminator>
    <Security_header>
        <name> Security_header </name>
        <attribute> Mandatory </attribute>
        <type> nibble </type>
        <value> 7 </value>
        <min> 0 </min>
        <max> F </max>
    </Security_header>
    <Security_header1>
        <name> Security_header </name>
        <attribute> Mandatory </attribute>
        <type> nibble </type>
        <value> 7 </value>
        <min> 0 </min>
        <max> F </max>
    </Security_header1>
    <Security_header2>
        <name> Security_header </name>
        <attribute> Mandatory </attribute>
        <type> nibble </type>
        <value> 7 </value>
        <min> 0 </min>
        <max> F </max>
    </Security_header2>
    <Security_header3>
        <name> Security_header </name>
        <attribute> Mandatory </attribute>
        <type> nibble </type>
        <value> 7 </value>
        <min> 0 </min>
        <max> F </max>
    </Security_header3>
</Attach_request>

Output::

$VAR1 = {
          'Security_header3' => {
                                'attribute' => ' Mandatory ',
                                'min' => ' 0 ',
                                'value' => ' 7 ',
                                'max' => ' F ',
                                'name' => ' Security_header ',
                                'type' => ' nibble '
                              },
          'Protocol_discriminator' => {
                                      'attribute' => ' Mandatory ',
                                      'min' => ' 0 ',
                                      'value' => ' 7 ',
                                      'max' => ' F ',
                                      'name' => ' Protocol_discriminator ',
                                      'type' => ' nibble '
                                    },
          'Security_header2' => {
                                'attribute' => ' Mandatory ',
                                'min' => ' 0 ',
                                'value' => ' 7 ',
                                'max' => ' F ',
                                'name' => ' Security_header ',
                                'type' => ' nibble '
                              },
          'Security_header' => {
                               'attribute' => ' Mandatory ',
                               'min' => ' 0 ',
                               'value' => ' 7 ',
                               'max' => ' F ',
                               'name' => ' Security_header ',
                               'type' => ' nibble '
                             },
          'Security_header1' => {
                                'attribute' => ' Mandatory ',
                                'min' => ' 0 ',
                                'value' => ' 7 ',
                                'max' => ' F ',
                                'name' => ' Security_header ',
                                'type' => ' nibble '
                              }
        };

My other question is:

  1. Is there any way i can manintain the order of the output, the same i gave in the input XML file ??
  • 1 1 Answer
  • 3 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-16T01:28:53+00:00Added an answer on May 16, 2026 at 1:28 am

    If you see the documentation of XML::Simple, it states that

    XML::Simple is able to present a simple API because it makes some assumptions on your behalf. These include:

    1. You’re not interested in text content consisting only of whitespace

    2. You don’t mind that when things get slurped into a hash the order is lost

    3. You don’t want fine-grained control of the formatting of generated XML

    4. You would never use a hash key that was not a legal XML element name

    5. You don’t need help converting between different encodings.

    For tree-based parsing, you could choose between the ‘Perlish’ approach of XML::Twig and more standards based DOM implementations – preferably one with XPath support.

    see also ‘Perl-XML FAQ‘ for more detail.

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

Sidebar

Related Questions

I'm using XML::Simple to parse an XML file which I then want to use
I'm using XML::Simple in Perl to parse through an XML file and I'm stuck
I am using the XML::Simple module to parse an XML file. When I run
I am using php's simple xml and xpath to parse an rdf xml file
I'd like to parse a simple, small XML file using python however work on
I am using Perl with XML::Simple to convert a hash into an XML document.
I'm creating an XML file using Perl and XML::Simple module. I successfully create the
I'm using Linq to parse a simple XML file into a var (ienumerable), I'm
I want to parse an XML file using Perl . I was able to
I am using a simple Perl script to parse XML and convert it to

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.