in reply to XML Parse, Spanish Elements
Hi Senik,
Personnally I'm not such a big fan of XML::Simple since the parsing into different types is very unconfortable. For example if a node contains one subnode, the subnode is a hash element in the node itself, with nore children it becomes an array..this is just an example, but is just to show that the parsetree is very difficult to navigate.
Myself I rather use XML::XPath. Here you can use xpath queries to navigate to the nodes you want and the result is very straightforward.
for you this would become something like :
Personnally I'm not such a big fan of XML::Simple since the parsing into different types is very unconfortable. For example if a node contains one subnode, the subnode is a hash element in the node itself, with nore children it becomes an array..this is just an example, but is just to show that the parsetree is very difficult to navigate.
Myself I rather use XML::XPath. Here you can use xpath queries to navigate to the nodes you want and the result is very straightforward.
for you this would become something like :
Hope this helps you, it saved my life more than once :)use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => 'test.xhtml'); my $nodeset = $xp->find('/noticias/noticia'); foreach my $noticia ($nodeset->get_nodelist) { my ($title,$fulltext,$date,$time) = ( $noticia->find('titulo')->string_value, $noticia->find('texto')->string_value, $noticia->find('fecha')->string_value, $noticia->find('hora')->string_value ) }
--
Cheers,
Rob
Cheers,
Rob
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: XML Parse, Spanish Elements
by jbrugger (Parson) on Feb 13, 2006 at 10:19 UTC | |
by misterb101 (Sexton) on Feb 13, 2006 at 11:11 UTC | |
by jbrugger (Parson) on Feb 13, 2006 at 11:45 UTC | |
by misterb101 (Sexton) on Feb 13, 2006 at 12:23 UTC | |
by jbrugger (Parson) on Feb 13, 2006 at 12:33 UTC |
In Section
Seekers of Perl Wisdom