Re: [xml] remove node from html document



On Wed, Feb 17, 2010 at 8:44 AM, andrew james
<andrew systemssingular com> wrote:
I have tried to xmlUnlinkNode, the result is that the loop through all nodes
is stopped at the unlinked node.

What is the reason for that stop?

How are you looping through the nodes? Are you sure you are not using
the unlinked node to determine the next node to process?

// Code like this is wrong:
xmlNodePtr node = first;
while (node != null) {
  if (some condition) {
    xmlUnlinkNode(node);
  }

  node = node->next; // ERROR! node is already unlinked and next may
not be valid
}

What you need to do is to save the "next" node _before_ unlink:

xmlNodePtr node = first;
while (node != null) {
  xmlNodePtr nextNode = node->next;
  if (some condition) {
    xmlUnlinkNode(node);
  }

  node = nextNode;
}

Csaba
-- 
Life is complex, with real and imaginary parts



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]