473,471 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Create 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 10482
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**************@tk2msftngp13.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**************@tk2msftngp13.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.SelectNodes("preceding-sibling::*").Count

"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> wrote in message
news:40******@news.microsoft.com...
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**************@tk2msftngp13.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.SelectNodes("preceding-sibling::*").Count

"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> wrote in message
news:40******@news.microsoft.com...
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**************@tk2msftngp13.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.SelectNodes("preceding-sibling::*").Count


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.SelectNodes("preceding-sibling::*").Count


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!PLEASEtkachenko.com> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
Marina wrote:
I found a way to do it via XPATH, something like this works:

node.SelectNodes("preceding-sibling::*").Count


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!PLEASEtkachenko.com> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
Marina wrote:
I found a way to do it via XPATH, something like this works:

node.SelectNodes("preceding-sibling::*").Count


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 misunderstanding. 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
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 misunderstanding. 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 #11

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? 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!PLEASEtkachenko.com> wrote in
message
news:ey**************@TK2MSFTNGP09.phx.gbl...
Marina wrote:
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 *

Code:
--------------------
http://tinyurl.com/fo2vs

--------------------
<----theres an advanced search for what ur looking for

--
deadman_freddy
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message797383.html

Mar 23 '06 #12

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

Similar topics

8
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...
0
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
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...
1
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
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
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...
4
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...
4
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
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...
0
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,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.