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 :
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
)
}
Hope this helps you, it saved my life more than once :)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|