我在 c# 中创建一个 xml 文档,使用以下代码创建
文件顶部的 xml 声明
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDoc.AppendChild(docNode);
我得到的xml声明如下:
<?xml version=\1.0\ encoding=\ utf-8\ ?>
我需要的是<?xml version="1.0" encoding="UTF-8"?>
尝试字符串操作以删除带有双引号的'\'字符,但值没有改变,我应该做些什么改变?这是创建剩余节点和所有节点的全部代码
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("urlset");
XmlAttribute attribute = xmlDoc.CreateAttribute("xmlns");
attribute.Value = "www.test.com";
rootNode.Attributes.Append(attribute);
xmlDoc.AppendChild(rootNode);
xmlDoc.Save("test-doc.xml");