Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: XML package for parsing values in the opening tag.

by dwatson06 (Friar)
on Apr 14, 2004 at 15:13 UTC ( [id://345088]=note: print w/replies, xml ) Need Help??


in reply to Re: XML package for parsing values in the opening tag.
in thread XML package for parsing values in the opening tag.

Thanks for the link to the specs.
I found another problem when a tag name contains an underscore.
<USER _City="testboro"></USER>
When I call the value...
print $xml->{USER}->{_CITY};
The following is printed out when calling the value...
"Use of uninitialized value"
Tempted to strip out the underscores but that would be poor coding standards plus an underscore could be used as an actual data value. I will go through the specs now.
DWW

Replies are listed 'Best First'.
Re: Re: Re: XML package for parsing values in the opening tag.
by waswas-fng (Curate) on Apr 14, 2004 at 18:28 UTC
    Dump the data with Data::Dumper and see what the problem is, most likely you will need to do print $xml->{'USER'}->{'_CITY'};


    -Waswas
Re: Re: Re: XML package for parsing values in the opening tag.
by gmpassos (Priest) on Apr 15, 2004 at 07:11 UTC
    This is because XML::Simple by default cut the root node, since on XML we only have one root tag. Also you typed _CITY, upercase, that is different of _City, since XML is case sensitive. So, you actually should use:
    print $xml->{_City} ;

    If you use XML::Smart it has an option to load a XML and parse all the nodes and attributes in upercase or lowercase:

    use XML::Smart ; my $xml = XML::Smart->new(q`<USER _City="testboro"></USER>` , uperta +g=>1 , uperarg=>1); print $xml->dump_tree_ok ;
    Output:
    $VAR1 = { 'USER' => { '_CITY' => 'testboro' } };

    Graciliano M. P.
    "Creativity is the expression of the liberty".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://345088]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-16 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found