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

Implementation of context using xpath for treeview (c#)

I have the following xml:

<?xml version="1.0" ?>
<course>
<globalProperties>
<externalMetadata>
<source>ADL</source>
<model>ADL SCORM 1.0</model>
</externalMetadata>
</globalProperties>
<block id="B1">
<identification>
<title>Yes/No Questions</title>
<description>This course has one lesson</description>
<labels>
<curricular>MODULE</curricular>
<developer>Me</developer>
</labels>
</identification>
<au id="A100001">
<externalMetadata>
<source>ADL</source>
<model>ADL SCORM 1.0</model>
</externalMetadata>
<identification>
<title>What is yes/no question</title>
<description>This slide describes the type of the question</description>
<labels>
<curricular>AU</curricular>
<developer>Me</developer>
</labels>
</identification>
<launch>
<location>slide1.htm</location>
</launch>
</au>
<au id="A100002">
<externalMetadata>
<source>ADL</source>
<model>ADL SCORM 1.0</model>
</externalMetadata>
<identification>
<title>Examples of yes/no questions</title>
<description>This slide provide examples</description>
<labels>
<curricular>AU</curricular>
<developer>Me</developer>
</labels>
</identification>
<launch>
<location>slide2.htm</location>
</launch>
</au>
<au id="A100003">
<externalMetadata>
<source>ADL</source>
<model>ADL SCORM 1.0</model>
</externalMetadata>
<identification>
<title>Test yourself</title>
<description>This slide checks what you have learned</description>
<labels>
<curricular>AU</curricular>
<developer>Me</developer>
</labels>
</identification>
<launch>
<location>slide3.htm</location>
</launch>
</au>
</block>
<block id="B2">
<identification>
<title>WH Questions</title>
<description>This course has one lesson</description>
<labels>
<curricular>MODULE</curricular>
<developer>Me</developer>
</labels>
</identification>
</block>
<block id="B3">
<identification>
<title>Other Question Types</title>
<description>This course has one lesson</description>
<labels>
<curricular>MODULE</curricular>
<developer>Me</developer>
</labels>
</identification>
</block>
</course>
I am trying to build a treeview that will hold the MODULEs and the AUs. When
I'm using the following code snippet:

foreach(XmlNode node in
doc.SelectNodes("//identification/labels[curricular='MODULE']/../title"))
{
t1 = new TreeNode(node.InnerText);
tree.Nodes.Add(t1);
foreach(XmlNode nod in
node.SelectNodes("//identification/labels[curricular='AU']/../title"))
{
t2 = new TreeNode(nod.InnerText);
t1.Nodes.Add(t2);

I'm getting the 3 AUs that are related to the first MODULE (titled "Yes/No
Questions") for all 3 modules. I want to get under each module only the AUs
that are under the same block - context. How should I implement that?
I was trying:
foreach(XmlNode node in
doc.SelectNodes("//block/identification/labels[curricular='MODULE']/../title"))
{
t1 = new TreeNode(node.InnerText);
tree.Nodes.Add(t1);
foreach(XmlNode nod in
node.SelectNodes("./au/identification/labels[curricular='AU']/../title"))
{
t2 = new TreeNode(nod.InnerText);
t1.Nodes.Add(t2);

but it didn't give me any au.

How can I do that?

Thanks

May 25 '06 #1
3 4979
Try this:

foreach (XmlNode node in
doc.SelectNodes("//identification/labels[curricular='MODULE']/../title"))
{
XmlNode temp =
node.SelectSingleNode("ancestor::block");
t1 = new TreeNode(node.InnerText);
tree.Nodes.Add(t1);
foreach (XmlNode nod in
temp.SelectNodes(".//identification/labels[curricular='AU']/../title"))
{
t2 = new TreeNode(nod.InnerText);
t1.Nodes.Add(t2);
}
}

May 25 '06 #2
Works perect, can you please explain?

Thanks

"vd*****@gmail.com" wrote:
Try this:

foreach (XmlNode node in
doc.SelectNodes("//identification/labels[curricular='MODULE']/../title"))
{
XmlNode temp =
node.SelectSingleNode("ancestor::block");
t1 = new TreeNode(node.InnerText);
tree.Nodes.Add(t1);
foreach (XmlNode nod in
temp.SelectNodes(".//identification/labels[curricular='AU']/../title"))
{
t2 = new TreeNode(nod.InnerText);
t1.Nodes.Add(t2);
}
}

May 26 '06 #3
XmlNode temp = node.SelectSingleNode("ancestor::block");

is selecting the node whose name "block" AND which is an Ancestor (look
at the xpath axes here -- ancestor:: )of the currently selected node
(which is "title" in this case). After that its looking for the child
node where curricular='AU'

hope that helps.

May 26 '06 #4

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

Similar topics

2
by: Eliza Zadura | last post by:
The following question is about XPath and context, as I am not sure I'm grasping the concept entirely and this is causing me some problems while working on my XSL transformation. I have checked...
4
by: Aaron Queenan | last post by:
How can I use the designer to add a context menu to a class which inherits from a control, e.g. treeview, without adding the context menu to a form? For example, to add a context menu with...
5
by: Dean L. Howen | last post by:
Dear friends, Could we determine when context menu should appear?
2
by: Steve Norman | last post by:
Hi, Is it possible to change the location of the IMPLEMENTATION line in ASP.NET when the treeview is rendered to the page? At present, the treeview always looks for the .htc file in a root...
1
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
2
by: Riki | last post by:
I'm stuck with an XPath query to produce a TreeView. From the data below, I want to select all the score elements having an IdIn of 2018, ***including their ancestors***. With the result, I want...
2
by: Lucky | last post by:
hi guys, i'm working on the context menu for the controls. the problem i'm facing right now is like this : i want to use one context menu for more then one controls lets say i want to use one...
7
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...
0
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. ...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.