<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>CPLRemoveXMLChild doesn't work (And I can't figure out how it's supposed to)</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>I had a bug in my program that I had to go<BR>
through the trouble of building GDAL and Xerces<BR>
to track down, and here's what I've come to:<BR>
<BR>
CPLRemoveXMLChild<BR>
<BR>
It's supposed to cleanly remove a child from<BR>
the parent's list of children. Instead, it<BR>
seems to simply set the parent's psChild to<BR>
NULL. Naturally, I decided to step through the<BR>
function to see what was happening.<BR>
<BR>
int CPLRemoveXMLChild( CPLXMLNode *psParent, CPLXMLNode *psChild ){<BR>
&nbsp;&nbsp;&nbsp; CPLXMLNode *psLast = NULL, *psThis;<BR>
&nbsp;&nbsp;&nbsp; if( psParent == NULL )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return FALSE;<BR>
&nbsp;&nbsp;&nbsp; for( psThis = psParent-&gt;psChild; psThis != NULL; psThis = psThis-&gt;psNext ){<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( psThis == psChild ) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( psLast == NULL )<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; psParent-&gt;psChild = psThis-&gt;psNext;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; psLast-&gt;psNext = psThis-&gt;psNext;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; psThis-&gt;psNext = NULL;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TRUE;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp; return FALSE;<BR>
}<BR>
<BR>
So, first off, it sets psLast to Null, never<BR>
changes it, then uses it in an if statement.<BR>
Then, the line of code which is now bound to<BR>
be executed when the child is found sets<BR>
psParent's child to the psChild's next sibling,<BR>
eliminating all of the previous sibling that<BR>
should still belong to the parent. The ultimate<BR>
result is that it eliminates all siblings up<BR>
until the psChild's (the psChild to be removed)<BR>
next sibling.<BR>
<BR>
As far as I can tell, this is what the method<BR>
should be doing reliably, and it's what I've<BR>
observed it doing in practice. This contradicts<BR>
what it is stated to be doing in the documentation.<BR>
<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>