Subject: | XML::DOM::Lite::Parser bugfixes |
Date: | Mon, 02 Feb 2009 23:42:19 +0100 |
To: | bug-XML-DOM-Lite [...] rt.cpan.org |
From: | Sascha Singert <sascha.singert [...] swm-software.de> |
Hi again,
this ticket extends/replaces ticket 42972, as this ticket describes the
same error.
first of all the changed lines:
* line 169
old => elsif ($elmnt =~ /($ElemTagCE)>$/o) {
now => elsif ($elmnt =~ /($ElemTagCE)$/o) {
reason => the variable $ElemTagCE already holds the ending >
* line 184
old => if ($elmnt =~ /\/$/) {
now => if ($elmnt =~ '/>$') {
reason => empty elements _always_ end with /> see w3c specs [44]
* line 185
old => $node = $self->_handle_element_node_end($elmnt);
now => $self->_handle_element_node_end($elmnt);
reason => $node holds the parent node which is wrong context for the
following lines; this causes a wrong internal list of available IDs
* line 249
old => $tagName =~ s/\/$//;
now => $tagName =~ s"[/>]"";
reason => needed because of change in line 169; some tag names end with
Show quoted text
> and some not; this corrects this behavior
the combination of these changes results in correct DOM and XPath
handling with XML::DOM::Lite with my testing xml
one changed line from the abobe only results in some funnier results, so
apply all changes before testing :-/
testing xml
--------------------------------------------------------
<config>
<menu>
<item id="hallo"></item>
<item id="welt" title="guck guck" />
<item id="blub" />
<item id="hallo2">
<item id="impressum" title="Impressum" />
</item>
</menu>
<hallo>
<welt>und so </welt>
</hallo>
<parameters>
<whitelist>
<parameter name="lang" value="de" />
<parameter name="id" />
<parameter name="js" value="0" />
</whitelist>
</parameters>
</config>
--------------------------------------------------------
the testing script
--------------------------------------------------------
$, = ', ';
my $doc = Parser->parse($xml);
## print root name
say $doc->documentElement->tagName; # line 249
say "=" x 50;
## select an id
my $node = $doc->getElementById('impressum');
say 'id = ' . $node->getAttribute('id'); # line 169 and 185
say "=" x 50;
## iterate over first level menu items
foreach my $item ( @{ $doc->selectNodes('/config/menu/item') } ) {
say 'id = ' . $item->getAttribute('id'); # works only with line 184
}
say "=" x 50;
## print all allowed parameter names
foreach my $node (@{
$doc->selectNodes("/config/parameters/whitelist/parameter") }) {
say 'param name = ' . $node->getAttribute('name');
}
say "=" x 50;
## show all available IDs
print 'available IDs => ';
say sort keys %{ $doc->{elements} };
--------------------------------------------------------
that's how my result looks like and must look like
--------------------------------------------------------
config
==================================================
id = impressum
==================================================
id = hallo
id = welt
id = blub
id = hallo2
==================================================
param name = lang
param name = id
param name = js
==================================================
available IDs => welt, blub, hallo, impressum, hallo2
--------------------------------------------------------
i've tested with perl 5.10 win32 and activated feature 'say'.
happy testing and maintenance :)
greets
sascha