perl, XML::Simple, hashes

S

Steven M. O'Neill

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.)
 
T

Thomas Wittek

Steven said:
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
 
S

Steven M. O'Neill

Thomas Wittek said:
Steven said:
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.
 
T

Thomas Wittek

Steven said:
Thomas Wittek said:
Steven said:
<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.
 
S

Steven M. O'Neill

Thomas Wittek said:
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 :|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top