Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IXMLDOMNode: Iterating thru childnodes?

304 views
Skip to first unread message

Stephan Schneider

unread,
Jun 27, 2003, 10:45:01 AM6/27/03
to
Hallo,

Env.: Delphi 6 UP 2

Because of prior post I follow the hints to use IXMLDOMDocument directly
instead of TXMLDocument.

My XML document has the following part-structure

<items>
<item>
<value>1</value>
<info>some hint</info>
<item>
<item>
<value>2</value>
<info>some other hint</info>
<item>
<item>
<value>3</value>
<info></info>
<item>
</items>

The variable nodeItems: IXMLDOMNode holds the "items" node. Now I want to
iterate thru the childnodes in a way like

for I := 0 to nodeItems.childNodes.length - 1 do
begin
nodeItem := nodeItems.childNodes[I];
nodeData := nodeItem.selectSingleNode('value');
Assert(Assigned(nodeData));
MyStringList.Add(nodeData.text);
end;

But this failed!

In my sample I have three item-node under the items-node, the length
property of nodeItems.childNodes has a value of greater than three. Why?
What have I to do to build up a list of the item-nodes under a items-node
(how has the iterating exactly to be)?

Regards
Stephan Schneider

Jeff Rafter

unread,
Jun 27, 2003, 11:25:49 AM6/27/03
to
> for I := 0 to nodeItems.childNodes.length - 1 do
> begin
> nodeItem := nodeItems.childNodes[I];
> nodeData := nodeItem.selectSingleNode('value');
> Assert(Assigned(nodeData));
> MyStringList.Add(nodeData.text);
> end;

You probably want to insert a check for

if nodeItems.childNodes[I].nodeType <> ntElement then continue;

I am not sure this is the problem but it may help.

Cheers,

--
Jeff Rafter
Defined Systems
XML Development and Web Hosting
http://xml.defined.net


0 new messages