特殊符号写入XML节点总结

这几天做一个网,在一个页面用到了Flash+xml效果,在后台生成XML的时候遇到一个问题:

小于大于符号写入时,以现变成了 < > 会自转换问题,于是在网上查了资料

            XmlElement path = xDoc.CreateElement("path");
            path.InnerText = "<![CDATA[flash/flowList/images/" + nSrc + "]]>";
            image.AppendChild(path);

            XmlElement description = xDoc.CreateElement("description");
            description.InnerText = "<![CDATA[<b>" + nTitle + "</b>]]>";
            image.AppendChild(description);

            XmlElement data2 = xDoc.CreateElement("data");
            data2.InnerText = " <![CDATA[]]>";
            image.AppendChild(data2);

改为

            XmlElement path = xDoc.CreateElement("path");
            path.InnerXml = "<![CDATA[flash/flowList/images/" + nSrc + "]]>";
            image.AppendChild(path);

            XmlElement description = xDoc.CreateElement("description");
            description.InnerXml = "<![CDATA[<b>" + nTitle + "</b>]]>";
            image.AppendChild(description);

            XmlElement data2 = xDoc.CreateElement("data");
            data2.InnerXml = " <![CDATA[]]>";
            image.AppendChild(data2);

这样就解决了, 核心: 将InnerText 改为 InnerXml 即可!

posted @ 2011-07-31 13:36 Mr.Tom 阅读(...) 评论(...) 编辑 收藏