469,323 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

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 10175
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by David McDivitt | last post: by
2 posts views Thread by Urs Vogel | last post: by
3 posts views Thread by Ed A | last post: by
3 posts views Thread by Kelvin Bryant | last post: by
4 posts views Thread by eggie5 | last post: by
1 post views Thread by Raul | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.