kulls has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,
I'm very basic beginner with xml-perl modules.I can't read the content of the tag which don't having any attributes.so my $hash was " $hash->{content}" failed with errors.
In this example,
If i don't have any attributes in the "  <txworld:general> " tag, then it is throw the error.
Suggest me,Is there is any rule in xml that, attribute is mandatory for the tags ??

Sample code
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use XML::SAX::Simple qw( XMLin); open (FH, "> test.xml") || die ("Could not create the file. $!"); print FH <<EOF; <?xml version="1.0"?> <txworld:data xmlns:txworld="www.toxinworld.com/xmlns"> <txworld:test name="name" version="1"> <txworld:general>100</txworld:general> </txworld:test> </txworld:data> EOF close (FH); my $hash=XMLin('test.xml'); print STDERR Dumper($hash); unlink("test.xml"); exit; =item --WITH_ATTRIBUT_OUTPUT-- $VAR1 = { 'xmlns:txworld' => 'www.toxinworld.com/xmlns', 'txworld:test' => { 'parent' => 'parent', 'version' => '1', 'name' => 'name', 'txworld:general' => { 'content' => '100', 'type' => '1' }, 'type' => 'type', 'alias' => 'alias' } }; --WITHOUT_ATTRIBUT_OUTPUT-- $VAR1 = { 'xmlns:txworld' => 'www.toxinworld.com/xmlns', 'txworld:test' => { 'parent' => 'parent', 'version' => '1', 'name' => 'name', 'txworld:general' => '100', 'type' => 'type', 'alias' => 'alias' } }; =cut

Replies are listed 'Best First'.
Re: XML::SAX::Simple module
by Devanchya (Beadle) on Dec 10, 2006 at 14:43 UTC
    The setup is a bit longer, but XML::LibXMLhas a bit more robust handling of xml data.

    What libXML does best is handle multiple parent and childnodes.

    Even smart people are dumb in most things...
Re: XML::SAX::Simple module
by Anonymous Monk on Dec 10, 2006 at 09:44 UTC
    Suggest me,Is there is any rule in xml that, attribute is mandatory for the tags ??
    There is no such rule. XML::Simple doesn't always do what you expect
Re: XML::SAX::Simple module
by Errto (Vicar) on Dec 11, 2006 at 05:31 UTC

    Forgive me for being glib, but is it not slightly ironic that there exists a module called XML::SAX::Simple?