473,397 Members | 1,969 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,397 software developers and data experts.

perl, XML::Simple, hashes

I have an xml structure like this:

<Meta name="fieldAttributes">
<MetaString name="name">SUB_PHONE</MetaString>
<MetaString name="value">999999999</MetaString>
</Meta>

<Meta name="fieldAttributes">
<MetaString name="name">SUB_NAME</MetaString>
<MetaString name="value">XML PLUS</MetaString>
</Meta>

I'm trying to parse it into a perl hash using XML::Simple
such that I can access data like:

print [something]->{SUB_PHONE} ;

and get back "9999999999";

(and likewise with the SUB_NAME, etc.)

Anyone have an idea on how to get th

(Not sure what this process is called, so I can't search Google
effectively -- any clue would be super.)

--
Steven O'Neill st****@panix.com
Brooklyn, NY
Is it Friday yet?
http://panix.com/~steveo/cgi/is-it-friday-yet.html
Aug 30 '07 #1
4 3252
Steven M. O'Neill schrieb:
I have an xml structure like this:

<Meta name="fieldAttributes">
<MetaString name="name">SUB_PHONE</MetaString>
<MetaString name="value">999999999</MetaString>
</Meta>

<Meta name="fieldAttributes">
<MetaString name="name">SUB_NAME</MetaString>
<MetaString name="value">XML PLUS</MetaString>
</Meta>

I'm trying to parse it into a perl hash using XML::Simple
such that I can access data like:

print [something]->{SUB_PHONE} ;

and get back "9999999999";
Just look at the XML::Simple docs:
http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm#ValueAttr_=>_[_names_]_#_in_-_handy

--
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: st*********@jabber.i-pobox.net
GPG: 0xF534E231
Aug 30 '07 #2
Thomas Wittek <ma**@gedankenkonstrukt.dewrote:
>Steven M. O'Neill schrieb:
>I have an xml structure like this:

<Meta name="fieldAttributes">
<MetaString name="name">SUB_PHONE</MetaString>
<MetaString name="value">999999999</MetaString>
</Meta>

<Meta name="fieldAttributes">
<MetaString name="name">SUB_NAME</MetaString>
<MetaString name="value">XML PLUS</MetaString>
</Meta>

I'm trying to parse it into a perl hash using XML::Simple
such that I can access data like:

print [something]->{SUB_PHONE} ;

and get back "9999999999";

Just look at the XML::Simple docs:
http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm#ValueAttr_=>_[_names_]_#_in_-_handy
I'm sorry, I should have mentioned that I've been reading the
XML::Simple docs for days. Can you you give me more more clue?
I still can't see how that section of the docs is analogous to
my situation.

--
Steven O'Neill st****@panix.com
Brooklyn, NY http://www.panix.com/~steveo
Aug 30 '07 #3
Steven M. O'Neill schrieb:
Thomas Wittek <ma**@gedankenkonstrukt.dewrote:
>Steven M. O'Neill schrieb:
>> <Meta name="fieldAttributes">
<MetaString name="name">SUB_PHONE</MetaString>
<MetaString name="value">999999999</MetaString>
</Meta>
[..]
print [something]->{SUB_PHONE} ;
and get back "9999999999";

I still can't see how that section of the docs is analogous to
my situation.
Oh sorry, you're right. The cases don't match as you're doing the
mapping on the content value instead of the attribute values.

As I don't see something like a "ValueContent" setting, you probably
have to do it manually.
Although it should be relatively easy to transform (map) the hash to a
hash that suits your needs.

Maybe you can get a good answer in a Perl group.

--
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: st*********@jabber.i-pobox.net
GPG: 0xF534E231
Aug 31 '07 #4
Thomas Wittek <ma**@gedankenkonstrukt.dewrote:
>Steven M. O'Neill schrieb:
>I still can't see how that section of the docs is analogous to
my situation.

Oh sorry, you're right. The cases don't match as you're doing the
mapping on the content value instead of the attribute values.

As I don't see something like a "ValueContent" setting, you probably
have to do it manually.
Although it should be relatively easy to transform (map) the hash to a
hash that suits your needs.
Yeah, thanks. I ended up reading in the XML and then changing
it into something else before running XML::Simple on it. Which
may or may not be the best solution. It sure feels hackish,
especially when I look at the regex it takes to do it :|

--
Steven O'Neill st****@panix.com
Brooklyn, NY http://www.panix.com/~steveo
Aug 31 '07 #5

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

Similar topics

13
by: Paulo Pinto | last post by:
Hi, does anyone know of a Python package that is able to load XML like the XML::Simple Perl package does? For those that don't know it, this package maps the XML file to a dictionary.
2
by: Bart Grieten | last post by:
Hi everyone, I'm not an expert Perl programmer and I'm trying to sort a hash. I know how to sort it by it's keys, but this time it should be sorted by its values. So if I have %hash = (...
0
by: Randy | last post by:
Is there a dotnet class that formats XML simple types. I'm making a xmldocument which has a timestamp element (among others). The format is: yyyy-MM-ddThh:mm:ss (which looks like...
6
by: Lindy | last post by:
I'm using VB .Net and am brand new to XML. I need to create an XML file with the following lines: <?xml version="1.0" encoding="UTF-8" ?> - <HC_DATA...
1
by: Miguel Manso | last post by:
Hi there, I'm a Perl programmer trying to get into Python. I've been reading some documentation and I've choosed Python has being the "next step" to give. Can you point me out to Python...
0
by: JohnLucas | last post by:
Hi all, I have just started working with the XML::Simple module to parse an XML file. I'm trying to pull some values from the file that I need in another program. The problem is that the XML...
1
by: kbozek | last post by:
I have an XSLT transform that will create an XML to XML transformation in the parent child format. I really want to output the elements and attributes on a single line such as: <image...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.