473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Perl modules for multi hierarchical XML processing

I hope my Subject makes sense:-)

I'm developing a front end form that generates an XML file that is the
nprocessed through a templating system. Unfortunately, the format the
XML needs to be in has proven to be difficult for me to reference with
any perl modules. Here's sample XML.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE record>
<record name="test" type="content">
<item name="Title">
<value>Testing</value>
</item>
<item name="Author">
<value>Ivan</value>
</item>
<item name="Author_Desc">
<value>Stumped</value>
</item>
<item name="List">
<value>
<item name="List_ID">
<value>1</value>
</item>
<item name="List_Title">
<value>List Title 1</value>
</item>
</value>
</item>
<item name="List">
<item name="List_ID">
<value>2</value>
</item>
<item name="List_Title">
<value>List Title 2</value>
</item>
</item>
</record>

Unfortunately, all elements have to be <item name="something">, and
when there are multiple instances of the same type, they have to have
the same name.

I have no problem accessing the individual elements using XML::Simple.

my $s = XML::Simple->new();
my $data = $s->XMLin($file);

print "$data->{item}->{Title}->{value}", etc.

My problem occurs when trying to iterate through the list items. I've
tried a few modules like XML::Parser, XML::XPath, and XML::Twig, but I
have yet to find a way to access a value based on one of the list
element attributes. My closest attempt has been with XPath. I'm able
to get the list blocks into nodes, but I get stuck from there.

my $x = XML::XPath->new( filename => $file );
my $nodeset = $x->findnodes( "/record/item[\@name='List']" );

foreach my $node ( $nodeset->get_nodelist )
{
##### Lost in Here ######
# Need List->List_ID->value and List->List_Title->value somehow
}

Would anyone have any advice on a solution with XPath, or any
assistance as to a better module choice? I would greatly appreciate
any help. Thanks,

Ivan Dwyer
Jul 20 '05 #1
1 2211
* Ivan Dwyer wrote in comp.text.xml:
My problem occurs when trying to iterate through the list items. I've
tried a few modules like XML::Parser, XML::XPath, and XML::Twig, but I
have yet to find a way to access a value based on one of the list
element attributes. My closest attempt has been with XPath. I'm able
to get the list blocks into nodes, but I get stuck from there.

my $x = XML::XPath->new( filename => $file );
my $nodeset = $x->findnodes( "/record/item[\@name='List']" );

foreach my $node ( $nodeset->get_nodelist )
{
##### Lost in Here ######
# Need List->List_ID->value and List->List_Title->value somehow
}


You should be able to

my $foo = $node->findnodes('item[@name="List_ID"]/value')->[0];
my $bar = $node->findnodes('item[@name="List_Title"]/value')->[0];

or maybe $node->findvalue(...) depending on the content model of these
elements.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
2
by: James Hull | last post by:
Hi All: I am new in the Perl world. So far I have installed cygwin and Perl 5.8.0 along with Perl DBI and DBD::Oracle modules. NowI am trying to install Perl Tk on my PC (Windows 2K). I have...
9
by: Dieter Vanderelst | last post by:
Dear all, I'm currently comparing Python versus Perl to use in a project that involved a lot of text processing. I'm trying to determine what the most efficient language would be for our...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
1
by: Me | last post by:
I need to get the past 5(x) months for certaing calculations. What I have is listed below: ######################################## my $year, $month_str, $month_int; foreach my $count...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: christianlandry | last post by:
Hi All, I have installed mysql on my powermac G5 (64 bits) and I installed perl DBD-mysql-4.005 and DBI-1.601 that I obtained from CPAN. The installation did not work and I kept getting error...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.