XML Help

2005-11-03 Thread Scott Taylor

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:

instead of
1234

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 ""; }

but even that doesn't work.

Cheers.

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: XML Help

2005-11-03 Thread Dermot Paikkos
On 3 Nov 2005 at 7:45, 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:
> 
> instead of
> 1234
> 
> 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 ""; }
> 
> but even that doesn't work.
> 
> Cheers.
> 

Not sure if I am qualified enough to answer this but I have had a bit 
of experience with XML::Simple. I would recommend using 
my $x = XMLin($fh, ForceArray => 1); 

if your not already as it helps generally. 

For the definedness of the data I guess 

my $foo = $x->{VEHICLE}->{STREETNUM}[n] # need n now that forcearray 
is on.
print if (defined($foo));

I would also say that the source file is wrong, it should read


HTH.
Dp.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: XML Help

2005-11-03 Thread Shawn Corey

Scott Taylor wrote:

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

but even that doesn't work.

Cheers.

--
Scott



What do you mean when you say it doesn't work? Are you getting something 
like this?


Use of uninitialized value in concatenation (.) or string ...

If so, try:

if( defined( $x->{VEHICLE}{STREETNUM} )){
  print "... ";
}
# You don't need to print ""

--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: XML Help

2005-11-03 Thread Scott Taylor

Dermot Paikkos said:
> On 3 Nov 2005 at 7:45, 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:
>> 
>> instead of
>> 1234
>>
>> 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 ""; }
>>
>> but even that doesn't work.
>>
>> Cheers.
>>
>
> Not sure if I am qualified enough to answer this but I have had a bit
> of experience with XML::Simple. I would recommend using
> my $x = XMLin($fh, ForceArray => 1);

That seems to have made a worse mess.  Somehow ends up in a huge loop. :(

> I would also say that the source file is wrong, it should read
> 

I read somewhere that  is correct syntax (same as )
but that doesn't mean that XLM::Simple likes it any better.

Unfortunately, I can't change the input file much.

Relly all I am looking for is a way to test if a Hash has a legitimate
value in it, or is it going yo output that way.

Thanks for your help.

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: XML Help

2005-11-03 Thread Bob Showalter

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:

instead of
1234

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]
 




Re: XML Help

2005-11-03 Thread Bob Showalter

Scott Taylor wrote:

Dermot Paikkos said:

I would also say that the source file is wrong, it should read




I read somewhere that  is correct syntax (same as )


You are correct. The two forms are exactly equivalent. see: 
http://www.w3.org/TR/REC-xml/#sec-starttags


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: XML Help

2005-11-04 Thread Scott Taylor

Bob Showalter said:
> Scott Taylor wrote:
>> Dermot Paikkos said:
>>>I would also say that the source file is wrong, it should read
>>>
>>
>>
>> I read somewhere that  is correct syntax (same as )
>
> You are correct. The two forms are exactly equivalent. see:
> http://www.w3.org/TR/REC-xml/#sec-starttags

Yeah, that's where I read it.  Still doesn't help me validate the hash
though. :(

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: XML Help

2005-11-04 Thread Scott Taylor

Bob Showalter said:
> 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:
>> 
>> instead of
>> 1234
>>
>> 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)

Thanks.  That works, and I don't even have to test it in my output. :)

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

I tried that an all I got was a bunch of trouble; the program seem to go
into a forever loop.  :(

I'm just using the data from the file, no attributes, does that matter?

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

Of course I did, it just doesn't make a lot of sense. :)

--
Scott

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]