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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:04:24+00:00 2026-06-15T18:04:24+00:00

I try to parse an xml document using XML::Simple perl parsing. I noticed, if

  • 0

I try to parse an xml document using XML::Simple perl parsing.
I noticed, if the document looks like:

<?xml version="1.0" encoding="UTF-8"?>
<fields>
  <field>
    <f1>1234</f1>
    <name>MyName1</name>
  </field>
</fields>

the result of print(Dumper($ref)); looks as expected:

$VAR1 = {
          'field' => {
                     'f1' => '1234',
                     'name' => 'MyName1'
                   }
        };

while if I have more than one list in the document:

<?xml version="1.0" encoding="UTF-8"?>
<fields>
  <field>
    <f1>1234</f1>
    <name>MyName1</name>
  </field>
  <field>
    <f1>567</f1>
    <name>MyName2</name>
  </field>
</fields>

the results looks like:

$VAR1 = {
          'field' => {
                     'MyName1' => {
                                  'f1' => '1234'
                                },
                     'MyName2' => {
                                  'f1' => '567'
                                }
                   }
        };

while expected results would be:

    $VAR1 = { [
              'field' => {
                         'f1' => '1234',
                         'name' => 'MyName1'
                       },
              'field' => {
                         'f1' => '567',
                         'name' => 'MyName2'
                       }
              ]
            };

what options of XML::Simple parser will prevent tag content substitution with the tag reference and use an array of <field> instead?

  • 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-15T18:04:24+00:00Added an answer on June 15, 2026 at 6:04 pm

    By default. XML::Simple names hash keys by the values of tags <name>, <key> and <id>. You can customize this behavior via KeyAttr setting.
    Thus, the code which produces the structure closest to what you expect is:

    #!/usr/bin/env perl
    use common::sense;
    use Data::Dumper;
    use XML::Simple;
    
    local $/ = undef;
    say Dumper XMLin(<DATA>, KeyAttr => []);
    
    __DATA__
    <?xml version="1.0" encoding="UTF-8"?>
    <fields>
      <field>
        <f1>1234</f1>
        <name>MyName1</name>
      </field>
      <field>
        <f1>567</f1>
        <name>MyName2</name>
      </field>
    </fields>
    

    And here is the output:

    $VAR1 = {
          'field' => [
                     {
                       'f1' => '1234',
                       'name' => 'MyName1'
                     },
                     {
                       'f1' => '567',
                       'name' => 'MyName2'
                     }
                   ]
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse a dom element. Element element: <?xml version=1.0 encoding=UTF-8?> <feed
I am testing against the following test document: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema> <sequence>
Hi guys I'm trying to parse an xml document using jquery but i keep
I am trying to parse a XML document using Xerces, but I cant seem
I've been trying to write a PHP script to parse an XML document using
This is my program, I am using STAX Parser to parse an XML document
The problem was: I'm parsing an XML document which validates, but when I try
I'm trying to parse a valid XML document in c# .NET using xPathNavigator .
I am using Visual Studio C# to parse an XML document for a file

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.