By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,957 Members | 1,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,957 IT Pros & Developers. It's quick & easy.

perl, XML::Simple, hashes

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.