Re: [xml] inconsistent behavior by "xmlChildElementCount()"

* JerryWRice wrote:
My program places this XML document into a zero-terminated char text 
buffer and creates a reader for it using "xmlReaderForDoc()".  Then I 
perform a series of "xmlTextReaderRead()" calls to advance my current 
node to element "<params>" on line 3.  I've confirmed I'm at the opening 
"<params>" node by using function "xmlTextReadName()" to verify.  While 
positioned at node "<params>", I call function "xmlChildElementCount()" 
and expect to get a child element count of "4" (there are four "<param>" 
sub-element nodes), but instead receive return count value of "3".

There is at least one step missing here since xmlTextReaderRead is part
of the reader interface while xmlChildElementCount is part of the tree
interface; you would need an xmlNodePtr for xmlChildElementCount but the
reader usually does not give you one. What are you using exactly to get
a xmlNodePtr? (In general, it would be much easier to help you with this
problem had you posted a minimal program to reproduce it.)

xmlChildElementCount simply iterates over the children of an element and
increments a counter for every element child, the only reason this would
give you a wrong number is when there is in fact no child element there,
which may well be the case if you have not read the children yet. If you
are using `xmlTextReaderCurrentNode` to get the xmlNodePtr then you've
misread its documentation and may be looking for `xmlTextReaderExpand`.
Björn Höhrmann · mailto:bjoern hoehrmann de ·
Am Badedeich 7 · Telefon: +49(0)160/4415681 ·
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · 

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