Scott Taylor wrote:
Hi All,

I'm using XML::Simple to parse a very simple XML file and dump the data
into hashes of hashes.

The problem I'm getting, is sometimes information is blank in the XMl
file; it looks like this:
<STREETNUM/>
instead of
<STREETNUM>1234</STREETNUM>

and when I print the hash:

print "$x->{VEHICLE}->{STREETNUM} ";

it returns: "HASH(blahblah)";

How do I test for this so it prints blank?  I've tried many things, the
most logical I could think of was:

if ($x->{VEHICLE}->{STREETNUM}){ print ... }
else { print ""; }

Two ways to do this:

1) use SuppressEmpty option. This will simply exclude the STREETNUM element if it is empty (no attributes and no content)

2) use ForceContent option. This will treat the STREETNUM element as a hash even if it is empty or contains only text. In this case you would use $x->{VEHICLE}{STREETNUM}{content} in your code.

#2 would probably be safer, because it would handle attributes to STREETNUM elements properly.

You can read more about these options in the XML::Simple documentation.

HTH

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to