473,581 Members | 3,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlNodeList - how to find out index of node in original child collection?

Hi,

Given a node, how can one find out its index in the collection of nodes it
belongs to?

Thanks
Nov 12 '05 #1
11 10520
There is no way to get this information. The same way there is no way to ask
an integer in an array which position in the array it came from.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Marina" <so*****@nospam .com> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Hi,

Given a node, how can one find out its index in the collection of nodes it
belongs to?

Thanks

Nov 12 '05 #2
There is no way to get this information. The same way there is no way to ask
an integer in an array which position in the array it came from.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Marina" <so*****@nospam .com> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Hi,

Given a node, how can one find out its index in the collection of nodes it
belongs to?

Thanks

Nov 12 '05 #3
That is not true.

I found a way to do it via XPATH, something like this works:

node.SelectNode s("preceding-sibling::*").Co unt

"Dare Obasanjo [MSFT]" <da***@online.m icrosoft.com> wrote in message
news:40******@n ews.microsoft.c om...
There is no way to get this information. The same way there is no way to ask an integer in an array which position in the array it came from.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Marina" <so*****@nospam .com> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Hi,

Given a node, how can one find out its index in the collection of nodes it belongs to?

Thanks


Nov 12 '05 #4
That is not true.

I found a way to do it via XPATH, something like this works:

node.SelectNode s("preceding-sibling::*").Co unt

"Dare Obasanjo [MSFT]" <da***@online.m icrosoft.com> wrote in message
news:40******@n ews.microsoft.c om...
There is no way to get this information. The same way there is no way to ask an integer in an array which position in the array it came from.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Marina" <so*****@nospam .com> wrote in message
news:OV******** ******@tk2msftn gp13.phx.gbl...
Hi,

Given a node, how can one find out its index in the collection of nodes it belongs to?

Thanks


Nov 12 '05 #5
Marina wrote:
I found a way to do it via XPATH, something like this works:

node.SelectNode s("preceding-sibling::*").Co unt


That's completely different index. That's a number of preceding siblings
in the source XML. You've asked for "index in the collection of nodes
it belongs to", which can be any depending on the collection.
E.g. when you select all "fruit" elements, above expression won't give
you index of an element in that collection.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #6
Marina wrote:
I found a way to do it via XPATH, something like this works:

node.SelectNode s("preceding-sibling::*").Co unt


That's completely different index. That's a number of preceding siblings
in the source XML. You've asked for "index in the collection of nodes
it belongs to", which can be any depending on the collection.
E.g. when you select all "fruit" elements, above expression won't give
you index of an element in that collection.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #7
I think that really depends what you think of as its index in the
collection. If we are talking about lot's of nested nodes, then what does
'index' really mean? Relative to what?

So to me, it means, in it's collection of siblings, because I don't see what
other index there could be.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:ey******** ******@TK2MSFTN GP09.phx.gbl...
Marina wrote:
I found a way to do it via XPATH, something like this works:

node.SelectNode s("preceding-sibling::*").Co unt


That's completely different index. That's a number of preceding siblings
in the source XML. You've asked for "index in the collection of nodes
it belongs to", which can be any depending on the collection.
E.g. when you select all "fruit" elements, above expression won't give
you index of an element in that collection.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #8
I think that really depends what you think of as its index in the
collection. If we are talking about lot's of nested nodes, then what does
'index' really mean? Relative to what?

So to me, it means, in it's collection of siblings, because I don't see what
other index there could be.

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:ey******** ******@TK2MSFTN GP09.phx.gbl...
Marina wrote:
I found a way to do it via XPATH, something like this works:

node.SelectNode s("preceding-sibling::*").Co unt


That's completely different index. That's a number of preceding siblings
in the source XML. You've asked for "index in the collection of nodes
it belongs to", which can be any depending on the collection.
E.g. when you select all "fruit" elements, above expression won't give
you index of an element in that collection.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #9
Marina wrote:
I think that really depends what you think of as its index in the
collection. If we are talking about lot's of nested nodes, then what does
'index' really mean?
Well, that's simple misunderstandin g. We used to think in terms of XPath
model and in XPath index (position) of a node in collection (nodeset)
is defined as just position of node in the nodeset (not a number of
preceding siblings). You can have a nodeset of anything (nested or not
nested nodes) and then iterate over it getting current position via
position() function.
So to me, it means, in it's collection of siblings, because I don't see what
other index there could be.


E.g. when a collection (nodeset) consists of all <apple> elements across
the whole document (//apple), then position of each <apple> element is
its position in that nodeset.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #10

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

Similar topics

8
9699
by: David McDivitt | last post by:
I need to set tabs on java generated pages. Pages have four sections: header, sidebar, body, and footer. The sidebar and body change dynamically. The tab key must go to anchors, fields, and buttons doing all in the header first, all in the sidebar second, etc. A base page contains includes for all the pieces and has the body tag. I am...
0
390
by: Marina | last post by:
Hi, Given a node, how can one find out its index in the collection of nodes it belongs to? Thanks
2
1716
by: Urs Vogel | last post by:
Hi When using XmlDocument, I can create nodes and attributes as I like. What I didn't achieve is changing the Value of a node (created with createElement), it claims that it's the wrong node type. When changing the InnerText, I loose all child nodes. When cloning the node and reassigning the child nodes of the original node to the cloned...
1
9644
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
3
1318
by: Ed A | last post by:
Hi all: Is there a way to replace a node and it's children? I tried using the ReplaceChild method but that seems to only replace the first child only!! Thanks Ed;;
3
7343
by: Kelvin Bryant | last post by:
I have tried the following code to set the index for a node. It seems to work when I use the root node index of 0. When I try a number greater than 0 I get an out of range error. I made sure that the tree was expanded, as well. treeView1.Focus(); treeView1.SelectedNode = treeView1.Nodes;
4
4617
by: SkyHook | last post by:
1. Under the topic "Select Nodes Using XPath Navigation" it says: "All XmlNodeList objects are synchronized with the underlying document, therefore if you ... modify the value of a node, that node is updated in the document it came from." 2. Under the topic "XmlNode.SelectNodes Method (String)" it says: "The XmlNodeList should not be...
4
7783
by: eggie5 | last post by:
Hi, I have an XmlNodeList and I need to reverse it. Just like Array.Reverse(), but it has to stay as an XmlNodeList. Any ideas?
1
2271
by: Raul | last post by:
Hi, I have the following code, which picks up 43 different nodes from my XML document XmlNodeList amortNodes = amortDoc.SelectNodes("// TValueAmortizationSchedule/AmortizationLine"); each node looks like this:
0
7861
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7789
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6548
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5669
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5358
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3817
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.