很奇怪的有关问题,把一些网址保存成xml文件,网址中的&总是被转换为&该怎么解决呢
很奇怪的问题,把一些网址保存成xml文件,网址中的&总是被转换为&,该如何解决呢
------解决思路----------------------
被转义了而已
xml文件里有它自己的语法
比如<>这种东西,你直接存这个,那标签不混乱了
既然你知道&会被替换成&,读取出来之后replace一下不就得了
------解决思路----------------------
这个是XML语法规定的,没法改变.你可以看看XML转义字符的相关资料
XmlDocument xmlDoc = new XmlDocument();
//创建Xml声明部分,即<?xml version="1.0" encoding="utf-8" ?>
XmlDeclaration xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
//创建根节点
XmlNode rootNode = xmlDoc.CreateElement("courses");
foreach (ListViewItem item in this.listView1.Items)
{
//创建course子节点
XmlNode courseNode = xmlDoc.CreateElement("course");
//创建一个属性
XmlAttribute nameAttribute = xmlDoc.CreateAttribute("name");
nameAttribute.Value = item.Text;
courseNode.Attributes.Append(nameAttribute);
//创建一个属性
XmlAttribute tagAttribute = xmlDoc.CreateAttribute("tag");
tagAttribute.Value = HttpUtility.HtmlDecode(item.Tag.ToString());
//xml节点附件属性
courseNode.Attributes.Append(tagAttribute);
rootNode.AppendChild(courseNode);
}
//附加根节点
xmlDoc.AppendChild(rootNode);
xmlDoc.InsertBefore(xmldecl, rootNode);
//保存Xml文档
xmlDoc.Save(fileName);
------解决思路----------------------
被转义了而已
xml文件里有它自己的语法
比如<>这种东西,你直接存这个,那标签不混乱了
既然你知道&会被替换成&,读取出来之后replace一下不就得了
------解决思路----------------------
这个是XML语法规定的,没法改变.你可以看看XML转义字符的相关资料