Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2006, 08:47 AM
ferdna ferdna is offline
Senior Member
 
Join Date: Jun 2001
Posts: 209
Default XML Node Count!??

how can i get the count of Top Nodes on an XML file!??

this gives me the count for child nodes:
Node1:= XMLDocument1.DocumentElement.ChildNodes[0];
Node1.ChildNodes.Count

I need to get the count for Parent Nodes!



thanks!
Reply With Quote
  #2  
Old 01-12-2006, 09:13 AM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: XML Node Count!??

You need to make a recursive function to sum up all the nodes:

[delphi]function GetNodeCount(XMLDocument: TXMLDocument): Integer;
var
Sum: Integer;

procedure CountNodes(Node: TXMLNode);
var
I: Integer;
begin
Inc(Sum, Node.ChildNodes.Count);
if Node.ChildNodes.Count > 0 then
for I := 0 to Node.ChildNodes.Count - 1 do
CountNodes(Node.ChildNodes[I]);
end;

var
I: Integer;
begin
Sum := XMLDocument.DocumentElement.ChildNodes.Count;
for I := 0 to XMLDocument.DocumentElement.ChildNodes.Count - 1 do
CountNodes(XMLDocument.DocumentElement.ChildNodes[I]);
Result := Sum;
end;[/delphi]

Or atleast something like that...didn't test it, but the algorythm should be alright

gLes
Reply With Quote
  #3  
Old 01-12-2006, 09:32 AM
ferdna ferdna is offline
Senior Member
 
Join Date: Jun 2001
Posts: 209
Default RE: XML Node Count!??

Found it...

XMLDocument1.DocumentElement.ChildNodes.Count
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:02 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.