Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

by mirod (Canon)
on Apr 14, 2004 at 14:20 UTC ( #345067=note: print w/replies, xml ) Need Help??

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

Any proper XML module will do that: XML::Parser (on its way to deprecation except as a low-level layer used by more convenient modules), XML::LibXML, XML::Simple, XML::Smart, XML::Twig, XML::SAX::PurePerl... XML::Parser::Lite is _not_ a real XML parser, it is designed to parse SOAP messages, which only use a subset of the XML recommendation.

As you mention you have problems with spaces in attributes, note that XML parsers are required to normalize attribute values, see The Annotated XML Specification. I don't think that's what your problem is here, but just in case, I thought I'd mention it.

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

Replies are listed 'Best First'.
Re: Re: XML package for parsing values in the opening tag.
by dwatson06 (Friar) on Apr 14, 2004 at 15:13 UTC
    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.
      Dump the data with Data::Dumper and see what the problem is, most likely you will need to do print $xml->{'USER'}->{'_CITY'};

      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 ;
      $VAR1 = { 'USER' => { '_CITY' => 'testboro' } };

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2023-09-26 08:32 GMT
Find Nodes?
    Voting Booth?

    No recent polls found