• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2008
  • Last Modified:

XML XPATH Select distinct elements

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()");

Thanks,
j.
<MACHINES>
    <CAR name='Toyota'>    
       <DATA>Some Data</DATA>
       <CATEGORY>JPY</CATEGORY>
    </CAR>
    <CAR name='Audi'>    
       <CATEGORY>ITL</CATEGORY>
    </CAR>
    <CAR name='Mazda'>    
       <CATEGORY>UK</CATEGORY>
    </CAR>
    <CAR name='Nissan'>    
       <CATEGORY>ITL</CATEGORY>
    </CAR>
   <CAR name='Nissan'>    
       <CATEGORY>ITL</CATEGORY>
    </CAR>
   <CAR name='Nissan'>    
       <CATEGORY>UK</CATEGORY>
    </CAR>
</MACHINES>

Open in new window

0
XPUSR
Asked:
XPUSR
  • 2
1 Solution
 
Geert BormansInformation ArchitectCommented:
you are close
//MACHINES/CAR[not(CATEGORY = preceding-sibling::CAR/CATEGORY)]/CATEGORY
0
 
XPUSRAuthor Commented:
Perfect. Thanks, j.
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now