Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2006

Tip: Looking for answers? Try searching our database.

XPath problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Riki - 20 Jul 2006 11:05 GMT
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 to fill a TreeView control.

This is my simplified data:

<?xml version="1.0" encoding="utf-8"?>
<Punten>
 <test Titel="TRAINING" >
   <test Titel="web" >
     <test Titel="Excel" >
       <test Titel="Eindtest Excel" >
         <score IdIn="1878" Score="12" />
         <score IdIn="2011" Score="14" />
         <score IdIn="2018" Score="15" />
       </test>
     </test>
     <test Titel="VB" >
       <test Titel="TEST1" >
         <score IdIn="2127" Score="20" />
         <score IdIn="2018" Score="17" />
         <score IdIn="2037" Score="11" />
       </test>
     </test>
     <test Titel="ASP" >
       <test Titel="Examen" >
         <score IdIn="1878" Score="28" />
         <score IdIn="2011" Score="-998" />
         <score IdIn="2018" Score="60" />
       </test>
     </test>
   </test>
   <test Titel="web2" >
     <test Titel="Excel" >
       <test Titel="Eindtest Excel" >
         <score IdIn="2042" Score="13" />
         <score IdIn="2091" Score="12" />
         <score IdIn="1818" Score="13" />
       </test>
     </test>
     <test Titel="Flash" Soort="Vak" >
       <test Titel="flintstones" >
         <score IdIn="2091" Score="6" />
         <score IdIn="2087" Score="10" />
         <score IdIn="2123" Score="5" />
       </test>
     </test>
   </test>
 </test>
</Punten>

This is the tree I want to produce (the scores with IdIn=2018):

<Punten>
 <test Titel="TRAINING" >
   <test Titel="web" >
     <test Titel="Excel" >
       <test Titel="Eindtest Excel" >
         <score IdIn="2018" Score="15" />
       </test>
     </test>
     <test Titel="VB" >
       <test Titel="TEST1" >
         <score IdIn="2018" Score="17" />
       </test>
     </test>
     <test Titel="ASP" >
       <test Titel="Examen" >
         <score IdIn="2018" Score="60" />
       </test>
     </test>
   </test>
 </test>
</Punten>

I have tried this XPath value (with an XmlDataSource):
//score[@IdIn='3234']/ancestor-or-self::*

It should give me what I want, but it produces an error in
TreeView.DataBindRecursive:
Object reference not set to an instance of an object

The query
//test[not(@Verwijderd='1')]/score[@IdIn='3234']
works without an error, but only produces the "scores" items

Does anybody know a working XPath query for this?

Any help with this problem is appreciated.

--

Riki
Dimitre Novatchev - 21 Jul 2006 02:01 GMT
This is not an XPath problem -- you need to ask in an appropriate newsgroup
about the issue you are having with the TreeView control.

Cheers,
Dimitre Novatchev

> I'm stuck with an XPath query to produce a TreeView.
>
[quoted text clipped - 91 lines]
>
> Riki
dickster - 27 Jul 2006 16:03 GMT
Some one please correct me if I'm wrong - I may be !

http://www.w3.org/TR/xpath states:

The primary syntactic construct in XPath is the expression. An
expression matches the production Expr. An expression is evaluated to
yield an object, which has one of the following four basic types:

   * node-set (an unordered collection of nodes without duplicates)
   * boolean (true or false)
   * number (a floating-point number)
   * string (a sequence of UCS characters)

The resultant fully formed XML you wish to see returned cannot be
returned by an xpath expression.

Your XPath Expression applied to your XMLDocument will return you a
NodeList.

I reckon you need to explore XSLT to transform the original XML into
the desired result.

Dickster

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.