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



Bjoem,

You must be psychic, as I was in fact using "xmlTextReaderCurrentNode()" to get the current node from the reader (prior to invoking "xmlChildElementCount()"). I understand your explanation, and upon changing my code to invoke "xmlTextReaderExpand()", I now receive the correct child count. Do you have a recommendation for a comprehensive tutorial type document for libxml2? The online HTML help is good, but the examples seem rather simple and sparse.

Thanks,

Jerry W. Rice

On 08/28/2010 01:42 PM, Bjoern Hoehrmann wrote:
* 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`.




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