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 / August 2007

Tip: Looking for answers? Try searching our database.

How to select parent based on a child value via XPath?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Art - 29 Aug 2007 19:38 GMT
Here is sample XML:

<Root>
  <A>
     <B>
        <C>Yes</C>
     </B>
  </A>
     :
  <A>
     <B>
        <C>No</C>
     </B>
  </A>
</Root>

There can be any # of nested <A> with values of either Yes or No. I would
like to select <A> node(s) based on value of <C>. In pseudo code:

Give me all <A> where <C> = "Yes" (or "No). So far I was able to select all
"Yes" (or "No") but these are <C> nodes and need their grandparents.
TIA
Peter Flynn - 29 Aug 2007 23:25 GMT
> Here is sample XML:
>
[quoted text clipped - 17 lines]
> Give me all <A> where <C> = "Yes" (or "No). So far I was able to select all
> "Yes" (or "No") but these are <C> nodes and need their grandparents.

In XPath, //A[descendant::C='Yes'] or possibly //C[.='Yes']/ancestor::A

///Peter
Signature

XML FAQ: http://xml.silmaril.ie/


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.