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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:00:29+00:00 2026-05-24T06:00:29+00:00

I want to parse an XML file, consisting, among others: <xml> <t> <name>object</name> <t1

  • 0

I want to parse an XML file, consisting, among others:

<xml>
<t>
    <name>object</name>
    <t1 name="a">A</t1>
    <t1 name="b">B</t1>
    <t2 name="c">C</t2>
</t>
...
</xml>

So, when I parse it with XML::Simple:

my $xml = new XML::Simple;
my $data = $xml->XMLin("data.xml");

I get that while $data->{t}->{object}->{t1}->{a}->{content} is expectedly “A”, I cannot get the “C” with $data->{t}->{object}->{t2}->{c}->{content}, because there is only one instance of “t2”.

In my script, I don’t want to have any differences between those two cases – I wish to get “C” exactly in the same way I got “A”.

How can that be done? I tried searching for the answer, but I only got to setting ForceArray to 1, but that didn’t solve the problem.

Thank you!

  • 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-24T06:00:30+00:00Added an answer on May 24, 2026 at 6:00 am

    Try to define in exact the forcearray, like this:

    my $data = $xml->XMLin("data.xml", forcearray=>['t2']);
    

    I believe this should work. If you are afraid that there might be instances of t which have only one instance of t1 as well, change it to ['t1', 't2'].

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

Sidebar

Related Questions

I have the following very simple XML file and I want to quickly parse
I am having one XML file and I want to parse only useful data
I have a simple but huge xml file like below. I want to parse
I want to parse some XML-file in Qt, but that file is located at
I am using GWT and want to parse an xml file, but I get
I am having one xml file and I want to parse it to get
I have a xml file. That I want to parse with NXXMLParser. I have
I want to parse a large XML file and I have two options: Perl
I want to parse an XML file with Java and validate it in the
I want to parse a XML file, change some attributes and write the results

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.