473,473 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

select nodes count

This is my xml sample:

<po>
<PurchaseOrderDetail>
<ProductLineItem>
<LineNumber>1</LineNumber>
<ProductIdentification>
<aaa>...</aaa>
<bbb />
</ProductIdentification>
<cc />
</ProductLineItem>
....
</PurchaseOrderDetail>
<PurchaseOrderDetail>
<ProductLineItem>
<LineNumber>2</LineNumber>
<ProductIdentification>
<aaa>...</aaa>
<bbb />
</ProductIdentification>
<cc />
</ProductLineItem>
....
</PurchaseOrderDetail>
</po>

I want to select "PurchaseOrderDetail" tag count, like this sample, I
should get "2". How should I get the count of it?

Thanks, David.

Nov 17 '05 #1
5 3156
I use selectnodes:

XmlElement root = doc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/PO/PurchaseOrderDetail");
int li_TotalCount = nodeList.Count;

But the li_TotalCount always "0"
I want get "2"...

Thanks, David.

Nov 17 '05 #2
Hi,
You can do it like this.

XmlNodeList nodeList = doc.GetElementsByTagName("PurchaseOrderDetail");
int li_TotalCount = nodeList.Count;

I think this will give you a count of 2.

Regards,
Angrez

Nov 17 '05 #3
David wrote:
I use selectnodes:

XmlElement root = doc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/PO/PurchaseOrderDetail");
int li_TotalCount = nodeList.Count;

But the li_TotalCount always "0"
I want get "2"...

Thanks, David.


Here you use "PO" in capitals, your example uses "po" in lowercase.
Is that a typo in your post? If not, then there is your problem: XML is case-sensitive
and yours has only "/po/PurchaseOrderDetail" nodes and no "/PO/PurchaseOrderDetail"

Hans Kesting
Nov 17 '05 #4
I got it!
Thank you, Angrez.

Nov 17 '05 #5
Thank you, Hans.
I solved it already.

David

Hans Kesting wrote:
David wrote:
I use selectnodes:

XmlElement root = doc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/PO/PurchaseOrderDetail");
int li_TotalCount = nodeList.Count;

But the li_TotalCount always "0"
I want get "2"...

Thanks, David.
Here you use "PO" in capitals, your example uses "po" in lowercase.
Is that a typo in your post? If not, then there is your problem: XML

is case-sensitive and yours has only "/po/PurchaseOrderDetail" nodes and no "/PO/PurchaseOrderDetail"
Hans Kesting


Nov 17 '05 #6

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

Similar topics

3
by: Michael Reiche | last post by:
Question on XSL expression Got this XML: <Body> <Page> <Line no="9" detail="true"> <onefield>onefieldstext</onefield> <twofield>twofieldstext</twofield> </Line>
9
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences...
8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
4
by: Larry R | last post by:
I am trying to use XPath (XSLT 1.0), EXSLT 1.1 (.Net) to select the nodelist consisting of the 'top n' nodes. THe counter is the count of item/value. Using a traditional for-each logic, the...
6
by: Nikhil Patel | last post by:
Hi all, Following is a portion of an XML document. I need to remove all nodes that belong to ns0 without deleting their child nodes. So in the following example , I want to delete "ns0:Proposal"...
3
by: someone | last post by:
Here is my code: TreeNodeCollection nodes = tvwFolders.Nodes; if (nodes.Count > 0) { // Select the root node tvwFolders.SelectedNode = nodes; } I hope there is an easier way. I looked at...
4
by: praveen | last post by:
I have a form with treeview control loaded from xml document,text box, two buttons named "Find" and "FindNext" and my treeview which looks like below. Details |__ policy status |__ created by...
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
10
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.