1 using System;
  
   2 
  
   3 int main()
  
   4 {
  
   5     System.Lex.FileMap fileMap;
  
   6     string query = "/philosophers/philosopher[@name=\'Socrates\']";
  
   7     string xml;
  
   8     xml.Append("<philosophers>\n").
  
   9         Append("    <philosopher name=\'Plato\'/>\n").
  
  10         Append("    <philosopher name=\'Aristotle\'/>\n").
  
  11         Append("    <philosopher name=\'Socrates\'/>\n").
  
  12         Append("</philosophers>\n");
  
  13     Result<UniquePtr<System.Xml.Document>> parseResult = System.Xml.ParseXmlDocumentContent(xml, "xml", fileMap);
  
  14     if (parseResult.Error())
  
  15     {
  
  16         Console.Error() << parseResult.GetErrorMessage() << endl();
  
  17         return 1;
  
  18     }
  
  19     System.Xml.Document* doc = parseResult.Value().Get();
  
  20     Result<System.UniquePtr<System.XPath.NodeSet>> nodeSetResult = System.XPath.EvaluateToNodeSet(query, doc);
  
  21     if (nodeSetResult.Error())
  
  22     {
  
  23         Console.Error() << nodeSetResult.GetErrorMessage() << endl();
  
  24         return 1;
  
  25     }
  
  26     System.XPath.NodeSet* nodeSet = nodeSetResult.Value().Get();
  
  27     int n = nodeSet->Count();
  
  28     for (int i = 0; i < n; ++i;)
  
  29     {
  
  30         System.Xml.Node* node = nodeSet->GetNode(i);
  
  31         if (node->IsElementNode())
  
  32         {
  
  33             System.Xml.Element* element = cast<System.Xml.Element*>(node);
  
  34             Console.Out() << element->GetAttribute("name") << endl();
  
  35         }
  
  36     }
  
  37     return 0;
  
  38 }