473,412 Members | 3,015 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,412 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 1725
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: 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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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...

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.