473,542 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is context node?

Hi folks,

I'm diving into XPathNavigator. SelectDescendan ts method. There's a boolean
type parameter matchSelf, and MSDN says "To include the context node in the
selection, true; otherwise, false". But I don't understand how to use it.
The sample code in MSDN is below, but I didn't find any difference of the
result while setting the value of this parameter to true and false
inspectively. So could anybody show me how to use the parameter to get
different result?

Any reply is appreciated!
XPathDocument document = new XPathDocument(" books.xml");
XPathNavigator navigator = document.Create Navigator();

XPathNodeIterat or nodes = navigator.Selec t("/bookstore/book");
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterat or nodesText =
nodesNavigator. SelectDescendan ts(XPathNodeTyp e.Text, false);

while (nodesText.Move Next())
{
Console.Write(n odesText.Curren t.Name);
Console.WriteLi ne(nodesText.Cu rrent.Value);
}
<bookstore>
<book genre="autobiog raphy" publicationdate ="1981-03-22"
ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate ="1967-11-17" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosop hy" publicationdate ="1991-02-15"
ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
Dec 8 '05 #1
2 2399
nicholas wrote:
I'm diving into XPathNavigator. SelectDescendan ts method. There's a boolean
type parameter matchSelf, and MSDN says "To include the context node in the
selection, true; otherwise, false". But I don't understand how to use it.
The sample code in MSDN is below, but I didn't find any difference of the
result while setting the value of this parameter to true and false
inspectively. So could anybody show me how to use the parameter to get
different result?


The example is terrible, unfortunately. It doesn't actually move the
first iterator on, so it's actually selecting the descendants of the
top level node. Also, by using the text node type, it's not going to
show the difference between true and false, as the selected node will
never be a text node. Here's a modified version which shows the
difference:

using System;
using System.Xml;
using System.Xml.XPat h;

class Test
{

static void Main()
{
XPathDocument document = new XPathDocument(" books.xml");
XPathNavigator navigator = document.Create Navigator();

XPathNodeIterat or nodes = navigator.Selec t("/bookstore/book");
nodes.MoveNext( );
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterat or elements =
nodesNavigator. SelectDescendan ts(XPathNodeTyp e.Element,
false);

while (elements.MoveN ext())
{
Console.WriteLi ne("Element name={0}",
elements.Curren t.Name);
}
}
}

This moves to the first node matching /bookstore/book, and then selects
all the element descendant nodes. As the second parameter is false, it
doesn't try to match the context node (the node you're searching for)
so the result doesn't include "Element name=book". If you change that
false to true, then it *does* include that.

Does that help?

Jon

Dec 8 '05 #2
Yes, that's really what I want to know. And I got the difference by
following your instruction.
Thanks very much for your kind-hearted help!

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
nicholas wrote:
I'm diving into XPathNavigator. SelectDescendan ts method. There's a
boolean
type parameter matchSelf, and MSDN says "To include the context node in
the
selection, true; otherwise, false". But I don't understand how to use it.
The sample code in MSDN is below, but I didn't find any difference of the
result while setting the value of this parameter to true and false
inspectively. So could anybody show me how to use the parameter to get
different result?


The example is terrible, unfortunately. It doesn't actually move the
first iterator on, so it's actually selecting the descendants of the
top level node. Also, by using the text node type, it's not going to
show the difference between true and false, as the selected node will
never be a text node. Here's a modified version which shows the
difference:

using System;
using System.Xml;
using System.Xml.XPat h;

class Test
{

static void Main()
{
XPathDocument document = new XPathDocument(" books.xml");
XPathNavigator navigator = document.Create Navigator();

XPathNodeIterat or nodes = navigator.Selec t("/bookstore/book");
nodes.MoveNext( );
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterat or elements =
nodesNavigator. SelectDescendan ts(XPathNodeTyp e.Element,
false);

while (elements.MoveN ext())
{
Console.WriteLi ne("Element name={0}",
elements.Curren t.Name);
}
}
}

This moves to the first node matching /bookstore/book, and then selects
all the element descendant nodes. As the second parameter is false, it
doesn't try to match the context node (the node you're searching for)
so the result doesn't include "Element name=book". If you change that
false to true, then it *does* include that.

Does that help?

Jon

Dec 9 '05 #3

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

Similar topics

1
2388
by: Vijay | last post by:
Hi Can anybody explain what self::* means in Xpath. I understand that "self" means the context node itself and * means any node type. So I thought self::* meant all the child nodes of context, but I some where read that self::* mean ".", the context itself. Can somebody please explain this. Vijay
4
11577
by: Phill | last post by:
Here's what I'm doing to make the right context mnue show up based on what node was cliked: private void tvwMenu_MouseUp(object sender, MouseEventArgs e) { //Select Node When Right Clicked & Set Context Menu To Use if( e.Button == MouseButtons.Right ) { TreeNode node = tvwMenu.GetNodeAt( new Point( e.X, e.Y ) ); if( node != null )
1
1427
by: Rory | last post by:
Hi - I've seen quite a few posts that almost match this but haven't found a solution that works. I have an explorer-like application with a treeview in the lefthand pane. When I right-click on a node, a context menu appears. How can I get different context menus to appear depending on which node is chosen. Here's my existing code: ...
2
3720
by: Claire | last post by:
I've a treeview control containing a root node with several children on a windows form. I select a node with a left mouse button click. I then select one of the other nodes with right mouse click to bring up my context menu. The Popup event of this enables menu items depending on the node selected. The new node highlights, and my context...
7
2799
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple type value to be the context of an XPath expression, by converting it to an XPath object -- either boolean, string or float. I do not see how...
0
3281
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. Provide following view properties to listview, through View menu a. Tile b. Icon
0
1147
by: EvilProject | last post by:
Hi im writing a class of a context menu where each menu item is linked to a Tree Node. I have a click event (that belongs to the context menu class ,not the menu item class) that it's event arguments contains a reference to the tree node linked to the menu item that was clicked. in the case that no menu item was selected, i want to fire this...
5
1434
by: Darin | last post by:
My tree is a menu with the parents the different applications (AR, AP, GL, etc), under each application could be another sub-menu (code file, reports), or an actual selectable field (customer file). So, i open AR (by clicking on the plus icon), left-click on customer file once (so it is highlighted in blue) then right click and select my...
32
2698
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template issue. A noddy mixin layer example should illustrate the issue... class Base { protected: int m_Field;
0
7726
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...
1
7329
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...
0
7675
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...
1
5257
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4884
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...
0
3384
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...
0
3385
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
948
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
626
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.