On 1/29/10 Fri Jan 29, 2010 1:34 PM, "Bruce Ferrell"
<[email protected]> scribbled:
> Perl monks,
>
> I have a wee problem I can seem to solve. I don't want to get into
> should XML::Simple be used, it's not relevant to my question... I don't
> think. Below is some very simple XML and below that the output after
> passing it through Dumper.
>
> As you can see phone2 is a blank tag (no contents) and it has the oddest
> representation in the Dumper output. How do I detect that?
It's a reference to an empty hash -- not that odd, considering that nested
tags in the XML generate nested hashes in the XML tree. I guess an undef
value would be better.
Use the ref function to see if the value is a reference to a hash. If it is,
get the number of keys (scalar keys %{$xml{message}->{phone2}}) and see if
there are zero elements.
>
> my $xml = XMLin ($data, ForceArray => 0)
>
> For non-blank tags <phone1></phone1> / $xml->{message}->{phone1} works
> fine. for a blank tag, I get other less interesting data.
>
> Suggestions?
>
>
>
> <event>
> <type>ADD</type>
> <message>
> <msgtype>PHONE</msgtype>
> <phone1>15105551212</phone1>
> <phone2></phone2>
> <wav>YES</wav>
> <custID>digits</custID>
> <status>ALERT</status>
> </message>
> </event>
>
>
> $VAR1 = {
> 'type' => 'ADD',
> 'message' => {
> 'status' => 'ALERT',
> 'phone1' => '15105551212',
> 'custID' => 'digits',
> 'phone2' => {},
> 'wav' => 'YES',
> 'msgtype' => 'PHONE'
> }
> };
>
>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/