473,396 Members | 1,916 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,396 software developers and data experts.

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 10476
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.