Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#14 ixml: get length of NULL nodeslist as 1

open
nobody
None
5
2004-06-29
2004-06-29
Zhang JianQiang
No

Description:

When a node have no child, the length of children
nodelist is retrieved as 1 but not 0.

Detail:

When using ixml handle xml documet of SOAP, I found
it puzzled me in retrieving a node's count of children.

I count the children of a node in such way:

1. using ixmlNode_getChildNodes() get the a nodelist of
node's children.
2. using ixmlNodeList_length() get how many nodes are
in the nodelist.
3. the gotten number is what i needed.

This process work well when the node has one or ore
children.

BUT: it not work when the node has no children. if
there is a node Znode has no children:

1. using ixmlNode_getChildNodes(Znode), get a nodelist
has NO item.
2. using ixmlNodeList_length() get length of the nodelist
(which actually has no item): 1 is returned.
3. as you known, the correct value should be 0.

Where is the bug?
I have read W3C's DOM docs and try to get the
answer:

1. using ixmlNode_getChildNodes() on a Znode( a node
has no children,for example, <node></node>), the
return value is not NULL, but is a NodeList struct
whose "item" element is NULL and "next" is NULL.

If ixmlNode_getChildNodes(Znode) return NULL
directly,It's maybe better.

2. using ixmlNodeList_length() on a ZnodeList( a
nodelist struct whose "item" is NULL and "next" is
NULL, in an other word, a nodelist has no containee.),
is return 1, but not 0.

If ixmlNodeList_length(ZnodeList) check whether the
nodelist struct's item is NULL to determine return 0 or
not, it will get the correct number.

Summary:

Citations from W3C's DOM doc
<<Document Object Model (DOM) Level 1 Specification
(Second Edition)>>:

1...Node Attribute childNodes :
A NodeList that contains all children of this node.
If there are no children, this is a NodeList
containing no nodes.
2...NodeList Attribute length:
The number of nodes in the list. The range of
valid child node indices is 0 to length-1 inclusive.

From above citations we can make the conclusions:

1. When used on Znode, ixmlNode_getChildNodes()
may return NULL directly. If it return a pointer
to nodeList structure with NULL as item and next,
we can not say it is incorrect, but it is something
trivial.

2. When used on ZnodeList, ixmlNodeList_length()
should check whether the nodelist struct's item is
NULL or not. if it is NULL, return 0.

Discussion