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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:20:56+00:00 2026-06-01T00:20:56+00:00

I currently have a Perl CGI script that parses incoming XML requests using XML::Simple

  • 0

I currently have a Perl CGI script that parses incoming XML requests using XML::Simple. The convention of the incoming XML is as follows:

<?xml version="1.0" encoding="utf-8" ?> 
<XMLRequest> 
  <CORE> 
    <CORE ID="14"> 
        <PARENT_ID>1</PARENT_ID> 
        <CORE_ID>14</CORE_ID> 
        <FORM_ID>1423</FORM_ID> 
        <SECURITY_ID>1</SECURITY_ID> 
        <AREA_ID>3</AREA_ID> 
        <SUB_PARENT_ID>1</SUB_PARENT_ID> 
        <SUB_AREA_ID>1</SUB_AREA_ID> 
    </CORE> 
    <CORE ID="15"> 
        <PARENT_ID>1</PARENT_ID> 
        <CORE_ID>15</CORE_ID> 
        <FORM_ID>1424</FORM_ID> 
        <SECURITY_ID>1</SECURITY_ID> 
        <AREA_ID>3</AREA_ID> 
        <SUB_PARENT_ID>1</SUB_PARENT_ID> 
        <SUB_AREA_ID>2</SUB_AREA_ID> 
    </CORE> 
  </CORE> 
</XMLRequest>

I need to get to the name/value pairs and from the convention, the name component is ‘CORE’ and the value being the value of ‘ID’. The challenge though is that ‘CORE’, in this convention represents a changing list of possible values. AS is, XMLin parses that XML so that the topmost and secondary ‘CORE’ are hashes, but then the ‘ID’ and the rest of the data as an array of hashes.

I’ve gone at it from the aspect of using the KeyAttr option of XML::Simple and listing all the possible variations of ‘CORE’ for the values, but this is a changing list so that’s not feasible. The other is just using nested Whiles and For statements to get down to the components needed, but that seems counter-intuitive. I started looking at XML::LibXML but it seems a bit more daunting to jump into.

Suggestions greatly appreciated.

  • 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-01T00:20:58+00:00Added an answer on June 1, 2026 at 12:20 am

    I find XML::Simple to be more awkward than simple, and would highly recommend that you progress to XML::LibXML or XML::Twig if only to get access to XPath expressions to access the XML DOM.

    Here is some code to do what I think you want with your XML. It finds all elements two levels below the root <XMLRequest> element that have an ID attribute and reports that element’s tag name and its ID attribute value. As you see it is done in only a couple of lines.

    use strict;
    use warnings;
    
    use XML::LibXML;
    
    my $xml = XML::LibXML->load_xml(string => <<XML);
    <?xml version="1.0" encoding="utf-8" ?> 
    <XMLRequest> 
      <CORE> 
        <CORE ID="14"> 
            <PARENT_ID>1</PARENT_ID> 
            <CORE_ID>14</CORE_ID> 
            <FORM_ID>1423</FORM_ID> 
            <SECURITY_ID>1</SECURITY_ID> 
            <AREA_ID>3</AREA_ID> 
            <SUB_PARENT_ID>1</SUB_PARENT_ID> 
            <SUB_AREA_ID>1</SUB_AREA_ID> 
        </CORE> 
        <CORE ID="15"> 
            <PARENT_ID>1</PARENT_ID> 
            <CORE_ID>15</CORE_ID> 
            <FORM_ID>1424</FORM_ID> 
            <SECURITY_ID>1</SECURITY_ID> 
            <AREA_ID>3</AREA_ID> 
            <SUB_PARENT_ID>1</SUB_PARENT_ID> 
            <SUB_AREA_ID>2</SUB_AREA_ID> 
        </CORE> 
      </CORE> 
    </XMLRequest>
    XML
    
    foreach my $node ($xml->findnodes('/XMLRequest/*/*[@ID]')) {
      printf "%s => %d\n", $node->nodeName, $node->getAttribute('ID');
    }
    

    output

    CORE => 14
    CORE => 15
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a perl script that runs forever on my server, checking a
I currently have a Perl script that runs an external command on the system,
I currently have a perl script that imports HTML and converts it to plain
I currently have this in my Ant build script: <exec dir=${basedir} executable=perl> <arg line=${basedir}/version.pl
I have a perl CGI script that needs to have a specific extensionless filename
I have application that works using Perl's CGI::Fast . Basically mainloop of the code
I am using CGI.pm version 3.10 for file upload using Perl. I have a
I am currently learning Perl. I have Perl hash that contains references to hashes
I have the following, simplest Perl CGI script: use strict; use warnings; use CGI();
Suppose I have a perl (or python) script that does something highly secretive; I'd

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.