473,772 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1758
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
//HsemServiceResp onse//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*******@yaho o.de> wrote in message
news:O8******** ******@TK2MSFTN GP12.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
//HsemServiceResp onse//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.
/HsemServiceResp onse/ServiceResponse/HSEMDomain/ManagedEntity
or at least
//HsemServiceResp onse//ServiceResponse//HSEMDomain/ManagedEntity
that way you get only <ManagedEntit y> 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*******@yaho o.de> wrote in message
news:Oi******** *****@TK2MSFTNG P14.phx.gbl...


Paul J Lay wrote:
I am selecting
//HsemServiceResp onse//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.
/HsemServiceResp onse/ServiceResponse/HSEMDomain/ManagedEntity
or at least
//HsemServiceResp onse//ServiceResponse//HSEMDomain/ManagedEntity
that way you get only <ManagedEntit y> 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
2895
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 try create a param using this search critieria it can never seem to locate what I am looking for. For example, check out the following XML file: ------------------------- <data> <aBlock id="1"> <tmpdata> <stringType>Hi</stringType>
3
7623
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> <data2>fdas</data2>
5
1533
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 like to extract nodes from the main.xml file, which were declared in role.xml. Example:
3
43596
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 TreeView.TopNode, but that is the top "visible" node. I would think that getting the absolute top node should
4
20384
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
21746
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 point that at a given node using the nodes name. I have the nodes name and it's parents name. Does anyone know a good way to find the node based on this information? Thanks a bunch.
13
9063
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 path "Users\Administrators\John Doe"? Thank you in advance! Andre Nogueira
1
2226
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 complete and "other times" I get incomplete stdout. E.g: - on boxA ffmpeg returns in ~25s; on boxB (comparable hardware,
5
3685
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 name="BlackRed" />
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6716
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.