木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2009-12-28 👁 11838 👍 0 💬 0 🔄 本站原创
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)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 GZipStream压缩/解压字符串改进版(C#) 下一篇 → IIS6.0配置使用GZip压缩页面文件