Re: [xml] Ask a question about xmlDocDumpFormatMemory() funciton.



* Xu Chunrong wrote:
THE PROBLEM is when I call xmlDocDumpFormatMemory(pdoc, &tmp,&len,0) my
program works OK,
but if I call xmlDocDumpFormatMemory(pdoc, &tmp,&len,1),  xml will find
unknown node,

  pcur = pcur->xmlChildrenNode;

I think you should use `children` instead, xmlChildrenNode is a legacy
macro.

   while (pcur != NULL)
   {
       if ((!xmlStrcmp(pcur->name, (const xmlChar *)"RequestID")))
         ...

Here you iterate over the child nodes without checking the node type.
There are several kinds of nodes, element nodes, comment nodes, text
nodes, and so on. If you have

  <foo>
   <bar/>
  </foo>

The 'foo' element has three children

  1. the white space before <bar/>
  2. <bar/>
  3. the white space after <bar/>

whereas you expect it to have only a single child element. Your code
would fail similarily if you had

  <foo><!----></foo>

You have to check for each node whether it is an element before you
can check whether it is a specific type of element.
-- 
Björn Höhrmann · mailto:bjoern hoehrmann de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 



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