Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 31st, 2009, 12:47 AM
Authorized User
Join Date: Nov 2007
Location: , , .
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Question XML::Simple is this possible


I'm a beginner in perl.
I'm trying to get an element value in xml.
I'm using XML::Simple.

BODY{font:x-small 'Verdana';margin-right:1.5em} .c{cursor:hand} .b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none} .e{margin-left:1em;text-indent:-1em;margin-right:1em} .k{margin-left:1em;text-indent:-1em;margin-right:1em} .t{color:#990000} .xt{color:#990099} .ns{color:red} .dt{color:green} .m{color:blue} .tx{font-weight:bold} .db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier} .di{font:small Courier} .d{color:blue} .pi{color:blue} .cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888} .ci{font:small Courier;color:#888888} PRE{margin:0px;display:inline}
<?xml version="1.0" ?> 
  <resultset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <field name="Customer_ID">1</field> 

    <field name="Name">ABC</field> 


     <field name="Customer_ID">2</field> 

    <field name="Name">DEF</field> 

I'm trying to get the customer_ID value.
my $myXML = XMLin("/myxml.xml");
my $custid = $myXML->{row}->{field=>['Name'=>'DEF']}->{field=>['Customer_ID']}
Can someone tell me what did I do wrong?
Reply With Quote
  #2 (permalink)  
Old September 3rd, 2009, 04:04 AM
Registered User
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Can you be a little clearer on just what you want?

Data::Dumper can help you here.
Your data structure looks like this:
$VAR1 = {
          'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
          'row' => [
                     'field' => {
                                'Name' => {
                                          'content' => 'ABC'
                                'Customer_ID' => {
                                                 'content' => '1'
                     'field' => {
                                'Name' => {
                                          'content' => 'DEF'
                                'Customer_ID' => {
                                                 'content' => '2'
This may be what you actually want:
use strict;
use warnings;
use XML::Simple;
my $myXML = XMLin("./myxml.xml");
print "\n";
foreach my $custid(@{$myXML->{row}}) {
	print "Customer ID: ".$custid->{'field'}->{'Customer_ID'}->{'content'}."\n";

Last edited by Leigh; September 3rd, 2009 at 04:08 AM..
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML::Simple parsing xml geek.shrek Perl 1 August 19th, 2009 10:32 PM
Need Xsl to Sort the following simple xml: Takashi321 XSLT 3 August 27th, 2007 11:54 AM
ch02 - Binding to a Simple XML Document Tophat BOOK: Beginning ASP.NET 1.0 7 August 17th, 2007 05:09 AM
simple xml / xslt example needed badgolfer ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2005 02:10 AM
Getting Simple XML Reading In ASP Happening munkimagik XML 1 June 19th, 2003 09:22 AM

All times are GMT -4. The time now is 09:31 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.