.NET Tips/XPath
System.Xml.XmlDocument クラスを使用すると DOM を使用して XML 文字列を読み込むことができますが、 XmlDocument#SelectNodes(), XmlDocument#SelectSingleNode() メソッドなどを使用すると、 XPath 式を使用してノードを取得することができます。
string xml = "<?xml version=\"1.0\"?><現在時刻>" + DateTime.Now.ToString() + "</現在時刻>"; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList nodeList = doc.SelectNodes("/現在時刻"); foreach (XmlNode node in nodeList) { Console.WriteLine(node.InnerText); }
2005年12月25日(日) 20:24:39 Modified by uguuxp