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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:33:23+00:00 2026-06-06T10:33:23+00:00

I have to write a Perl script to convert an XML file into a

  • 0

I have to write a Perl script to convert an XML file into a CSV file. I’ve already written something simple in one context, and need to enhance it for a different dataset, and can’t quite figure out what to do.

I’m using XML::Simple.

Here is one record of the data:

<custom-objects xmlns="http://www.demandware.com/xml/impex/customobject/2006-10-31">
    <custom-object type-id="emailBackInStockHistory" object-id="bczCAiaag0APcaaacLsvpJRmzW">
        <object-attribute attribute-id="email">some@email.com</object-attribute>
        <object-attribute attribute-id="emailSentAt">2010-04-10T09:00:01.000+0000</object-attribute>
        <object-attribute attribute-id="productID">someprodid</object-attribute>
        <object-attribute attribute-id="requestedAt">2010-04-09T10:07:54.000+0000</object-attribute>
        <object-attribute attribute-id="siteID">someSITEid</object-attribute>
    </custom-object>
</custom-objects>

Using the Data::Dumper module I see that the data is parsed as this:

'custom-object' => [
    {
        'type-id'          => 'emailBackInStockHistory',
        'object-id'        => 'bczCAiaag0APcaaacLsvpJRmzW',
        'object-attribute' => [
            {
                'attribute-id' => 'email',
                'content'      => 'some@email.com'
            },
            {
                'attribute-id' => 'emailSentAt',
                'content'      => '2010-04-10T09:00:01.000+0000'
            },
            {
                'attribute-id' => 'productID',
                'content'      => 'someprodid'
            },
            {
                'attribute-id' => 'requestedAt',
                'content'      => '2010-04-09T10:07:54.000+0000'
            },
            {
                'attribute-id' => 'siteID',
                'content'      => 'someSITEid'
            }
        ]
    },

Here is some code that I’ve tried to use to perform this export:

foreach $o (@{$data->{'custom-object'}}) {
    print $o->{'type-id'},   ",";
    print $o->{'object-id'}, ",";
    print $o->{'custom-object'}->{'object-attribute'}->{'email'}, ",";
    print "\n";

The type-id and object-id attributes get output properly, but I can’t figure out how to print the data from the object-attribute reference.

  • 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-06T10:33:25+00:00Added an answer on June 6, 2026 at 10:33 am

    You need to iterate over your object-attribute array-ref like your doing with the custom-object array-ref. Also have a look at Text::CSV for a more robust way of creating csv files.

    foreach my $obj ( @{ $data->{'custom-object'} } ) {
        print $obj->{'type-id'}, ",";
        print $obj->{'object-id'}, ",";
        foreach my $attr ( @{ $obj->{'object-attribute'} } ) {
            if ( $attr->{'attribute-id'} eq 'email' ) {
                print $attr->{'content'}, ",";
            }
        }
        print "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a simple Perl script that reads a *.csv, places
I have a quite simple perl script, that in one function does the following:
I have a perl script (or any executable) E which will take a file
I have these two lines in an old Perl script. When I write the
my perl script is multi threaded and in each thread i have to write
Suppose I have a Perl script, namely mytest.pl. Can I run it by something
I am attempting to write a one-line Perl script that will toggle a line
I'm trying to write a perl script to search through a text file, find
I'm trying to write a perl script that removes whitespace from XML tags, but
I have been trying to write a perl script to get all of the

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.