C#设置/读取CDATA 节点内容

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml("<xml><description><![CDATA[木子屋:http://www.mzwu.com/]]></description></xml>");

//读取
Console.WriteLine(xmlDoc.SelectSingleNode("//description").FirstChild.InnerText);

//设置
xmlDoc.SelectSingleNode("//description").FirstChild.InnerText = "谷歌:http://www.g.cn/";

//显示
Console.WriteLine(xmlDoc.InnerXml);

XPath没有提供直接获取CDATA 节点的语法,只能变通下,先定位到其父节点,再获取子节点来获取。

评论: 0 | 引用: 0 | 查看次数: 9628
发表评论
登录后再发表评论!