08 December 2016

XML Path Örnekleri

//string path = Application.StartupPath;
 string path2 = Directory.GetParent
 (Application.ExecutablePath).Parent.Parent.FullName;
 XmlDocument xdoc = new XmlDocument();
 xdoc.Load(path2 + "\\XmlData\\CdCollection.xml");
 
//Query 1
 XmlNode xeCd2 = xdoc.SelectSingleNode(@"catalog/cd[@ID=2]/company");
 Console.WriteLine(xeCd2.InnerText);
 Console.ReadLine();

//Query 2
 XmlNode xe = xdoc.SelectSingleNode("catalog/cd[@ID=2]");
 Console.WriteLine(xe.SelectSingleNode("title").InnerText);

//Query 3
 XmlNodeList xlist= xdoc.SelectNodes("catalog/cd");
 foreach (XmlNode node in xlist)
 {
 XmlNode xnTitle = node.SelectSingleNode("title");
 Console.WriteLine(xnTitle.InnerText);
 }

//Query 4
 XmlNodeList FiyatiDokuzdanBuyukOlanlar = xdoc.SelectNodes("catalog/cd[price>'9']");
foreach (XmlNode node in FiyatiDokuzdanBuyukOlanlar)
 {
 XmlNode xnTitle = node.SelectSingleNode("title");
 Console.WriteLine(xnTitle.InnerText);
 }