Menu

#1 phantom StdClass in XML tree

open
nobody
None
5
2005-09-11
2005-09-11
Beat
No

A small problem has as side-effect that generating the XML tree with
DOMIT gives an additional class with index -1.

while adding some XML parametering to a joomla/mambo
component, I have hit a trivial bug in the DOMIT lite library.
Details below and corrected file is attached.

Thanks again, and Best Regards,
Beat

In: includes/domit/xml_domit_lite_parser.php in method:
function &appendChild(&$child)

This:
//append child
$numNodes = $this->childCount;
$prevSibling =& $this->childNodes[($numNodes - 1)];
// <---- has nasty side effects.... auto-created wrong
childnodes[-1]

$this->childNodes[$numNodes] =& $child;

//set next and previous relationships
$child->previousSibling =& $prevSibling;
// <---- in that case, this has also nasty side
effects....
$prevSibling->nextSibling =& $child;
// ...this one auto-creates a stdClass with one object
reference...

is wrong at the begining of the XML tree generation. Proposing to
change it as follows (changes in bold):

//append child
$numNodes = $this->childCount;
if ($numNodes>0) $prevSibling =& $this-
>childNodes[($numNodes - 1)]; //BB: was bug auto-created wrong
childnodes[-1]: added IF

$this->childNodes[$numNodes] =& $child;

//set next and previous relationships
if (isset($prevSibling)) {
//BB: added this line and the else part to finish correcting bug
$child->previousSibling =& $prevSibling;
$prevSibling->nextSibling =& $child;
} else {
unset($child->previousSibling);
$child->previousSibling = null;
$this->firstChild =& $child;
}

Why this bothers:

Simply doing:

$xmlDoc =& new DOMIT_Lite_Document();
if ($xmlDoc->loadXML( $this->_path, false, true )) {

generates in the childNodes array a unwanted childNodes[
-1]=stdClass().

this in turn makes errors and warnings when calling:

if ($element = &$xmlDoc->getElementsByAttribute(
$attr,$attrvalue,true )) {
$xmlDoc->setDocumentElement($element);

to cut out sub-trees of the xml tree.

Discussion

  • Beat

    Beat - 2005-09-11

    corrected xml_domit_parser.php

     
  • Beat

    Beat - 2005-09-11

    Corrected lite version of the parser (first seen problem here!)

     

Log in to post a comment.