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

Select Nodes

I am using the XmlDocument Select Nodes method and it seems to work OK
except that it returns embedded nodes in the collection when I only want the
nodes that are not embedded. For example I have a statement as follows:

nodes = doc.SelectNodes(\\Node1\\Node\\DesiredNode);

It gives me back in the collection all the DesiredNode tags. If I select
retrieve the nth node as follows

node = nodes[n-1];

It gives me the correct node and all DesiredNodes that are embedded within
the nth node. So if I ask for the first node it gives me the first node
which includes about 5 embedded DesiredNodes. When I ask for the second
DesiredNode node it gives me the first embedded node within the first
DesiredNode. I would like to retrieve a DesireNode nodes collection which
only retrieves nodes which are not embedded. Embedded DesiredNodes cannot
be retrieved directly and can only be seen as embedded within the
non-embedded nodes. How do I do that? I can't seem to find that in the
XPath or XmlDoocument documentation. Please advise. Thanks for your help.

Best Regards,

Paul J. Lay
Nov 12 '05 #1
6 1716
Hi Paul,

In an XPath query, we need to seperate the nodes using slash '/' and with
namespace prefixes.

nodes = doc.SelectNodes("/ns1:Node1/ns2:Node/ns3:DesiredNode);

If that still doesn't work, would you please post your code and sample xml
document here, so that I can try to reproduce this on my machine?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #2


Paul J Lay wrote:
I am using the XmlDocument Select Nodes method and it seems to work OK
except that it returns embedded nodes in the collection when I only want the
nodes that are not embedded. For example I have a statement as follows:

nodes = doc.SelectNodes(\\Node1\\Node\\DesiredNode);


What is that? It is not even syntactically correct XPath. It might be
that you are using // instead of the \\ you have above and in that case
// selects all descendants while you might only need the children which
can be done in XPath using /DesiredNode instead of //DesiredNode.
If that doesn't help could you post an example XML document and then
describe which elements or nodes you want to select with XPath?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3
Yes you are correct. I am selecting
//HsemServiceResponse//ServiceResponse//HSEMDomain//ManagedEntity. I get
back a collection of more than 500 nodes. When I retrieve the first node
(node = nodes[0]) I get back the first ManagedEntity node and it includes
8 embedded ManagedEntity nodes. When I retrieve the second node I get back
the 1st embedded ManagedEntity node within the first ManagedEntity node. I
want to receive a collection of only the ManagedEntity nodes which are not
embedded. Embedded nodes can be seen only by retrieving the parent node in
which they are embedded. I believe this is possible if you know the correct
XPATH syntax. Thanks for your help.

Best Regards,

Paul J Lay

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:O8**************@TK2MSFTNGP12.phx.gbl...


Paul J Lay wrote:
I am using the XmlDocument Select Nodes method and it seems to work OK
except that it returns embedded nodes in the collection when I only want
the nodes that are not embedded. For example I have a statement as
follows:

nodes = doc.SelectNodes(\\Node1\\Node\\DesiredNode);


What is that? It is not even syntactically correct XPath. It might be that
you are using // instead of the \\ you have above and in that case //
selects all descendants while you might only need the children which can
be done in XPath using /DesiredNode instead of //DesiredNode.
If that doesn't help could you post an example XML document and then
describe which elements or nodes you want to select with XPath?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #4


Paul J Lay wrote:
I am selecting
//HsemServiceResponse//ServiceResponse//HSEMDomain//ManagedEntity. I get
back a collection of more than 500 nodes. When I retrieve the first node
(node = nodes[0]) I get back the first ManagedEntity node and it includes
8 embedded ManagedEntity nodes. When I retrieve the second node I get back
the 1st embedded ManagedEntity node within the first ManagedEntity node. I
want to receive a collection of only the ManagedEntity nodes which are not
embedded. Embedded nodes can be seen only by retrieving the parent node in
which they are embedded. I believe this is possible if you know the correct
XPATH syntax.


As I said, in XPath // selects descendants so I guess you want / instead
e.g.
/HsemServiceResponse/ServiceResponse/HSEMDomain/ManagedEntity
or at least
//HsemServiceResponse//ServiceResponse//HSEMDomain/ManagedEntity
that way you get only <ManagedEntity> elements which are child nodes of
<HSEMDomain> elements.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #5
That worked! Thanks so much for your prompt reply. Do you know where there
is a good reference on XPath syntax? I have been trying to find one. All I
have found so far are incomplete snippets. Thanks again.

Best Regards,

Paul J Lay

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:Oi*************@TK2MSFTNGP14.phx.gbl...


Paul J Lay wrote:
I am selecting
//HsemServiceResponse//ServiceResponse//HSEMDomain//ManagedEntity. I get
back a collection of more than 500 nodes. When I retrieve the first node
(node = nodes[0]) I get back the first ManagedEntity node and it
includes 8 embedded ManagedEntity nodes. When I retrieve the second node
I get back the 1st embedded ManagedEntity node within the first
ManagedEntity node. I want to receive a collection of only the
ManagedEntity nodes which are not embedded. Embedded nodes can be seen
only by retrieving the parent node in which they are embedded. I believe
this is possible if you know the correct XPATH syntax.


As I said, in XPath // selects descendants so I guess you want / instead
e.g.
/HsemServiceResponse/ServiceResponse/HSEMDomain/ManagedEntity
or at least
//HsemServiceResponse//ServiceResponse//HSEMDomain/ManagedEntity
that way you get only <ManagedEntity> elements which are child nodes of
<HSEMDomain> elements.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #6
Hi Paul,

You can check the w3c xpath specifications.

http://www.w3.org/TR/xpath

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #7

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

Similar topics

2
by: RanDeep | last post by:
I have two nodes that both exist underneath the root node. They are linked, however, in the sense that one of the nodes contains a copy of an id that is used to refer to the other. However, when I...
3
by: Michael | last post by:
Hello, I am creating an XSL that is going to create a report from XML we recieve from another system. The XML would look like: <report> <page> <header1> <data1>asdf</data1>...
5
by: Chris | last post by:
Hi, Maybe I've got a strange question. I've got a XML document (main.xml) with several nodes. Additional I've another XML docuement (role.xml), with allowed nodes. In a XSL-File I just would...
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: G Uljee | last post by:
How can I find and select an specific item in an treeview control? I want to create a search feature on my treeview. Thanks in advance, Gaby
2
by: Wes | last post by:
I have a treeview that I am continually added nodes to. Each time a new node is added I would like to select that node. Is this possible? I have looked at selectedNode, but I don't know how to...
13
by: André Nogueira | last post by:
Hi there. I know you can view a node's fullpath property, but is it posible to select a node using its path? Like, tell the treeview that the node that should be selected is the node with the...
1
by: Christopher DeMarco | last post by:
Hi all... I've written a class to provide an interface to popen; I've included the actual select() loop below. I'm finding that "sometimes" popen'd processes take "a really long time" to...
5
by: AdrianGawrys | last post by:
Hi Guys, I have an xml similar to this one: <?xml version="1.0" encoding="UTF-8"?> <SystemUpdate ForceUpdate="false" > <A ForceUpdate="false"> <Book name="Black" /> <Book...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.