次のコードを使用して、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");