新鲜、有趣,互联生活。令狐葱。

2006/11/22

使用XPathDocument 读取XML文件

一般比较常用的读取xml 好像用DOM,不过使用XPathDocument  效果也不错。

        public string GetXMLString(string xmlFilename, string xpath)
        {
            string xmlString = null;

            XPathDocument doc = new XPathDocument(xmlFilename);
            XPathNavigator nav = doc.CreateNavigator();
            XPathNodeIterator iter = nav.Select(xpath);
            iter.MoveNext();
            xmlString = iter.Current.Value;
            xmlString = iter.Current.GetAttribute("name", "");
            iter = null;
            nav = null;
       
            return xmlString;
        }
详细可参见MSDN

没有评论: