Help on Filtering XML nodes ???

G

Guest

Dear all,

I have a csv file data which has been read and populate on a dataset object.
then I need to bind part of the content of the dataset to a treeview control.
I have read that XML format is particular usefull to be bind to a treeview
as it handle nodes. So I have try to save my dataset content into a xml file.
The content of that file is as follow :

- <NewDataSet>
- <REC_INFO>
<FILE_NAME>REC00001.CSV</FILE_NAME>
<RECIPE_CLASS>Pipe</RECIPE_CLASS>
<RECIPE_NAME>25 x 2.5 mm</RECIPE_NAME>
<LINE_NAME>LP602</LINE_NAME>
<GROUPE_NAME>LP602</GROUPE_NAME>
<MODIFIED>02/11/2004 15:15:04</MODIFIED>
</REC_INFO>
- <REC_INFO>
<FILE_NAME>REC00002.CSV</FILE_NAME>
<RECIPE_CLASS>Profile</RECIPE_CLASS>
<RECIPE_NAME>Coling</RECIPE_NAME>
<LINE_NAME>LP602</LINE_NAME>
<GROUPE_NAME>LP602</GROUPE_NAME>
<MODIFIED>02/11/2004 15:15:04</MODIFIED>
</REC_INFO>

Then I have founc a sample function that bind xmlnodes to treeview node but
then in my case it displays all of them. I am only interesting to display ina
treeview the XML node named RECIPE_CLASS

I have seen that for filtering nodes we need to us Xpath but how to define
my filter then
How can I do that ?

Thanks for your help
regards
serge
 
G

Guest

Thnaks for the info , I will give a try..

by the way if I apply my XPath string as you said /RECE_INFO/RECIPE_CLASSE
I should retrieve only those node right?

Ok then I add my first node in my treeview collection. Then things that
might happen is that I could have more that one RECIPE_CLASS node value. , so
I can I verify if my node is already existing in treenode collection in order
to ad it or not ?

I have try to use the Contains(myNode) function but it always return false
even if the node ahas really be added.

Any suggestion ?

thnaks for your help
serge
 
S

Sean Hederman

serge calderara said:
Thnaks for the info , I will give a try..

by the way if I apply my XPath string as you said /RECE_INFO/RECIPE_CLASSE
I should retrieve only those node right?
Yes.

Ok then I add my first node in my treeview collection. Then things that
might happen is that I could have more that one RECIPE_CLASS node value. ,
so
I can I verify if my node is already existing in treenode collection in
order
to ad it or not ?

I have try to use the Contains(myNode) function but it always return false
even if the node ahas really be added.

What's probably happenning is like the following:
TreeNode firstNode = new TreeNode("Hello");
myTree.Nodes.Add(firstNode);
TreeNode secondNode = new TreeNode("Hello");
bool exists = myTree.Nodes.Contains(secondNode));

The variable exists will always be false, since we are dealing with two
different TreeNode objects. They may have the same text, but the objects are
not the same. You could just iterate the tree view to see if any nodes at
that level have the specified text. If it's a large number of nodes, some
kind of hashed collection would probably be ideal. Alternatively

//RECE_INFO/RECIPE_CLASSE[not(.=preceding::RECIPE_CLASSE)]

But this would imply that the XML is sorted by RECIPE_CLASSE. You can do
this by using XPathExpression and adding RECIPE_CLASSE to AddSort.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top