title: Reading distinct values from XML using XPath
body: <p>I have an XML in the following format:</p>
  
  <pre><code>&lt;Accounts&gt;
     &lt;Account Number="1"   DebitAmount="1000" Amount="2827561.95" /&gt; 
     &lt;Account Number="225" DebitAmount="2000"  Amount="12312.00" /&gt; 
     &lt;Account Number="236" DebitAmount="London"    Amount="457656.00" /&gt; 
     &lt;Account Number="225" DebitAmount="London"    Amount="23462.40" /&gt; 
     &lt;Account Number="236" DebitAmount="Bangalore" Amount="2345345.00" /&gt; 
  &lt;/Accounts&gt;
  </code></pre>
  
  <p>How do I retreive the unique Account Numbers using  Xpath? ie, I want to get the values 1, 225 and 236.</p>
  
  <p>This is what I did:(I'm using Delphi 2007...)</p>
  
  <pre><code>Const XmlStr =
  ' &lt;Accounts&gt;
     &lt;Account Number="1"   DebitAmount="1000" Amount="2827561.95" /&gt; 
     &lt;Account Number="225" DebitAmount="2000"  Amount="12312.00" /&gt; 
     &lt;Account Number="236" DebitAmount="London"    Amount="457656.00" /&gt; 
     &lt;Account Number="225" DebitAmount="London"    Amount="23462.40" /&gt; 
     &lt;Account Number="236" DebitAmount="Bangalore" Amount="2345345.00" /&gt; 
  &lt;/Accounts&gt;';
  
   function GetAccountNumbers:TList;
   Var
     XMLDOMDocument  : IXMLDOMDocument;
     accounts : IXMLDOMNodeList;
    accountdetail :IXMLDOMNode;
     i:Integer
     list :TList
   begin
     Result:=TList.Create;
     XMLDOMDocument:=CoDOMDocument.Create;
     XMLDOMDocument.loadXML(XmlStr);
     accounts:= XMLDOMDocument.SelectNodes(''./Accounts 
    /Account[not(@Number=preceding-sibling/ Account /@Number)]');
    for i := 0 to accountdetails.length - 1 do begin
       accountdetail := accountdetails.item[i];
       //omitting the "&lt;&gt;nil" checks...
       list.Add(accountdetail.attributes.getNamedItem('Number').Nodevalue;
    end;
   end;
  </code></pre>
  
  <p>But this returns no nodes(accountdetails.length=0). Please let me know what I am missing here.</p>
  
  <p>Thanks,</p>
  
  <p>Pradeep</p>