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

  • Home
  • SEARCH
  • 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 9274901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:27:44+00:00 2026-06-18T16:27:44+00:00

I am getting into XML::Simple and have had a problem with the XML::Simple module

  • 0

I am getting into XML::Simple and have had a problem with the XML::Simple module choking when parsing one record. The perl code is below…..

#!/usr/bin/perl
# use module
use warnings;
use strict;
use XML::Simple;
use Data::Dumper;

# create object
my $xml = new XML::Simple;

# read XML file
my $data = $xml->XMLin("owners.xml");

foreach my $e (@{$data->{Owner}})
{
     print $e->{OwnerId}->{OwnerCik}."\n";
     print $e->{OwnerId}->{OwnerName}."\n";
     print "\n";
}

When I use this XML, it works beautifully…

<?xml version="1.0"?>
<ownershipDocument>
    <Owner>
        <OwnerId>
            <OwnerCik>0001234878</OwnerCik>
            <OwnerName>PUBLIC JOHN Q</OwnerName>
        </OwnerId>
    </Owner>
    <Owner>
        <OwnerId>
            <OwnerCik>0001234877</OwnerCik>
            <OwnerName>PUBLIC JANE Q</OwnerName>
        </OwnerId>
    </Owner>
</ownershipDocument>

It’s when I have a one record that I have issues… the XML below is an example…

<?xml version="1.0"?>
<ownershipDocument>
    <Owner>
        <OwnerId>
            <OwnerCik>0001234878</OwnerCik>
            <OwnerName>PUBLIC JOHN Q</OwnerName>
        </OwnerId>
    </Owner>
</ownershipDocument>

The error I get when parsing this is…..

Not an ARRAY reference at ./so_parse.pl line 14.

I thought the solution would be to use ForceArray and I changed this to include ForceArray..

my $data = $xml->XMLin("so_single.xml", ForceArray=>1);

Now I get ……

Not a HASH reference at ./so_parse.pl line 16.

Admittedly, I’m a little hazy on complex data structures but what I’m trying to solve is how to parse these owners when we only have one.

Any help would be great!
Janie

  • 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-18T16:27:45+00:00Added an answer on June 18, 2026 at 4:27 pm

    Try this:

    my $data = $xml->XMLin("so_single.xml", ForceArray=>['Owner']);
    

    It should only force the array on the ‘Owner’ elements.

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

Sidebar

Related Questions

getting some problem into my spring application. I have very fairly simple spring beans,
I have run into an exasperating problem getting a Java service client to communicate
I have a pretty simple one for you today, but it certainly has had
Am trying to insert XML into XML Column.. getting following error: . Msg 6819,
Just getting into the NoSQL stuff so forgive me if this is a simple
I've just started getting into Catalyst, and I've been finding it really helpful. One
I am just getting into javascript and d3.js. Please excuse the simple question, but
I'm just getting into using REST and have started building my first app following
Hi I have one xml file successfully parsed my before. now i am change
I am simply trying to retrieve an attribute from XML into my Perl program.

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.