Re: [xml] Possible bug on content addition then node deletion.




Well, after testing and manual walking through the tree with a debugger, I noticed the difference - your code indeed works, and so does mine if I create the doc your way. But, I use xmlReadMemory in my code, and it produces this structure if I use the xml example as an input:

NODE <Something> = (name->'Something', content->0):

NODE 'Dogs usually say bark but I say' = (name->'text', content->'Dogs usually bark but I say'):


....  and so on.

So xmlReadMemory does not join content to tags even if it is adjacent to them. Which explains the behaviour observed - the content ('Dogs usually say bark but I say') in your example actually *belongs* to 'Something' as content; with xmlReadMemory it isn't, it is separated into a separate text node.
        I shall have to concatenate adjacent text nodes myself, then...


Regards,
                Jose.

--
Arguing with an engineer is like wrestling with a pig in mud.
After a while, you realize the pig is enjoying it.

On 23 Nov 2004, at 17:05, Kasimier Buchcik wrote:

Hi,

Jose Commins wrote:
    Still does the same thing with xmlNodeGetContent.

Just for the fun of using the Delphi libxml2 bindings:

procedure test();
var
  doc: xmlDocPtr;
  someNode, replNode: xmlNodePtr;
  buf: pxmlChar;
begin
  doc := xmlNewDoc(pxmlChar('1.0'));
  xmlNewTextChild(xmlNodePtr(doc), nil, pxmlChar('Something'),
    pxmlChar('Dogs usually say bark but I say '));
  someNode := xmlDocGetRootElement(doc);
  replNode := xmlNewTextChild(someNode, nil, pxmlChar('Replace'),
    pxmlChar('value'));
  xmlNodeAddContent(someNode, pxmlChar('blah'));

  writeln('--- xmlDocDumpMemory ---');
  xmlDocDumpMemory(doc, buf, nil);
  writeln(string(buf));
  xmlFree(buf);

  xmlUnlinkNode(replNode);
  xmlFreeNode(replNode);

  writeln('--- xmlNodeGetContent ---');
  buf := xmlNodeGetContent(someNode);
  writeln(string(buf));
  xmlFree(buf);

  xmlFreeDoc(doc);
end;

.... produces:
----------------------------------
P:\tests\nodeContent>nodeContent
--- xmlDocDumpMemory ---
<?xml version="1.0"?>
<Something>Dogs usually say bark but I say <Replace>value</Replace>blah</Something>

--- xmlNodeGetContent ---
Dogs usually say bark but I say blah
----------------------------------


P:\tests\nodeContent>xmllint --version
xmllint: using libxml version 20615CVS2219

I can't reproduce it here.

Regards,

Kasimier
















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