473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

xml counts

Is there a method/funciton in xmldocument
to count all nodes in a xml doc

or do i have to write my own

thanks
DAveL
Sep 18 '08 #1
5 1131
on 18-9-2008, DaveL supposed :
Is there a method/funciton in xmldocument
to count all nodes in a xml doc

or do i have to write my own

thanks
DAveL
On XmlDocument there is a SelectNodes() method that accepts an XPath
expression and returns a list of matching nodes. Get the Count of that.

Hans Kesting
Sep 19 '08 #2
DaveL wrote:
Is there a method/funciton in xmldocument
to count all nodes in a xml doc

or do i have to write my own
It depends on the kind of nodes you are looking for
xmlDocumentInstance.SelectNodes("//*").Count
gives you the number of all element nodes
xmlDocumentInstance.SelectNodes("//@*").Count
the number of all attribute nodes (in the XPath 1.0 data model where
namespace declarations are not attributes).

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 19 '08 #3
Right, but it only has the count of its nodes
child node mite have child node example

<ROOT>
<ONE>
<TWO/>
<THREE/>
<TWO/>

</ONE>
<TWO>
<THREE/>
</TWO>
</ONE>
</ROOT>

In the above i have a total of 6 nodes, i wonderd if XmlDocument Has a
Count For all Nodes in a complete Document
Seems Like i'll need to Write a method/function for recursion through the
document

Dave L

"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:eG**************@TK2MSFTNGP02.phx.gbl...
on 18-9-2008, DaveL supposed :
>Is there a method/funciton in xmldocument
to count all nodes in a xml doc

or do i have to write my own

thanks
DAveL

On XmlDocument there is a SelectNodes() method that accepts an XPath
expression and returns a list of matching nodes. Get the Count of that.

Hans Kesting


Sep 19 '08 #4
It happens that DaveL formulated :
Right, but it only has the count of its nodes
child node mite have child node example

<ROOT>
<ONE>
<TWO/>
<THREE/>
<TWO/>

</ONE>
<TWO>
<THREE/>
</TWO>
</ONE>
</ROOT>

In the above i have a total of 6 nodes, i wonderd if XmlDocument Has a Count
For all Nodes in a complete Document
Seems Like i'll need to Write a method/function for recursion through the
document

Dave L

"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:eG**************@TK2MSFTNGP02.phx.gbl...
>on 18-9-2008, DaveL supposed :
>>Is there a method/funciton in xmldocument
to count all nodes in a xml doc

or do i have to write my own

thanks
DAveL

On XmlDocument there is a SelectNodes() method that accepts an XPath
expression and returns a list of matching nodes. Get the Count of that.

Hans Kesting

The snippet below produces a result of 7 (I changed the XML somewhat to
make it well-formed)

public static void RunSnippet()
{
string s = @"<ROOT>
<ONE>
<TWO>
<THREE/>
</TWO>

</ONE>
<ONE>
<TWO>
<THREE/>
</TWO>
</ONE>
</ROOT>";

XmlDocument xml = new XmlDocument();
xml.LoadXml(s);

XmlNodeList nl = xml.SelectNodes("//*");
Console.WriteLine(nl.Count);

}

Hans Kesting
Sep 19 '08 #5
Thanks alot hans
Much Appriciated
DaveL

"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:OU*************@TK2MSFTNGP03.phx.gbl...
It happens that DaveL formulated :
>Right, but it only has the count of its nodes
child node mite have child node example

<ROOT>
<ONE>
<TWO/>
<THREE/>
<TWO/>

</ONE>
<TWO>
<THREE/>
</TWO>
</ONE>
</ROOT>

In the above i have a total of 6 nodes, i wonderd if XmlDocument Has a
Count For all Nodes in a complete Document
Seems Like i'll need to Write a method/function for recursion through the
document

Dave L

"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:eG**************@TK2MSFTNGP02.phx.gbl...
>>on 18-9-2008, DaveL supposed :
Is there a method/funciton in xmldocument
to count all nodes in a xml doc

or do i have to write my own

thanks
DAveL

On XmlDocument there is a SelectNodes() method that accepts an XPath
expression and returns a list of matching nodes. Get the Count of that.

Hans Kesting


The snippet below produces a result of 7 (I changed the XML somewhat to
make it well-formed)

public static void RunSnippet()
{
string s = @"<ROOT>
<ONE>
<TWO>
<THREE/>
</TWO>

</ONE>
<ONE>
<TWO>
<THREE/>
</TWO>
</ONE>
</ROOT>";

XmlDocument xml = new XmlDocument();
xml.LoadXml(s);

XmlNodeList nl = xml.SelectNodes("//*");
Console.WriteLine(nl.Count);

}

Hans Kesting


Sep 22 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
5
by: Steven Bethard | last post by:
I have a list of dictionaries. Each dictionary holds counts of various 'words', e.g.: py> countdicts = I need to select dicts with the constraint that the number of each 'word' totalled...
0
by: Andres | last post by:
Hi, i have this questions: 1 - How can i create user counts in Windows with C#? 2 - How can i set permissions for the counts with C#? 3 - How can i start an application with one of the created...
5
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
1
by: Randy K | last post by:
I have a table with some 35000 records and I need some help sorting it out. The goal is to get counts of failures modes oraganized by serial number. the table is set up roughly like this. s/n ...
1
by: AccessHunter | last post by:
Hi, I have a report for Judges and their cases Numbers, grouped by Judge Name,the detail starts on a new page every time a judge changes. On the Judge footer I am displaying Count of Total no of...
9
by: ncyankeefan | last post by:
I am trying to get the number of specific alerts for each month of the year. I would like to get these counts in one query or subquery. There is a date field in table so I can specifically get the...
3
by: geraldjr30 | last post by:
hi, i am very new to php. started learning 3 days ago. i have figured out how to list MS Access table output in table format in PHP. but i need to know how i can have some output like...
3
by: Wildster | last post by:
Hi, How can you count x and y as seperate counts from the same field? i.e. A table has the field Gender and I want to have one count which counts the number of records with 'male' as the...
2
by: Superfreak31 | last post by:
Hello All, I need help with a SQL Query. I have a table with a StateId and PartNumber. I'll be joining some tables to get the state name from the StateId and Part Description from the Part...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.