XML XPATH Select distinct elements

Posted on 2008-11-17
Last Modified: 2013-11-18
Hi Experts,

How do I select (using C# System.XML) the distinct categories using XPATH into an array?

I am thinking that something along the following line should do the trick, however I ain't having much luck:

xmlNodes = xmlDoc.SelectNodes("//MACHINES/CAR/CATEGORY[not(CATEGORY/text()=preceding::node/text())]/text()");


    <CAR name='Toyota'>    

       <DATA>Some Data</DATA>



    <CAR name='Audi'>    



    <CAR name='Mazda'>    



    <CAR name='Nissan'>    



   <CAR name='Nissan'>    



   <CAR name='Nissan'>    




Open in new window

Question by:XPUSR
    LVL 60

    Accepted Solution

    you are close
    //MACHINES/CAR[not(CATEGORY = preceding-sibling::CAR/CATEGORY)]/CATEGORY

    Author Comment

    Perfect. Thanks, j.
    LVL 60

    Expert Comment

    by:Geert Bormans

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now