469,347 Members | 1,999 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,347 developers. It's quick & easy.

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 3125
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Paulo Pinto | last post: by
2 posts views Thread by Bart Grieten | last post: by
reply views Thread by Randy | last post: by
1 post views Thread by Miguel Manso | last post: by
reply views Thread by JohnLucas | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.