0

I am creating an xml document in c# used the following code to create

xml declaration at top of the file

  XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    xmlDoc.AppendChild(docNode);

and I am getting the xml declaration as follows:

<?xml version=\1.0\  encoding=\ utf-8\ ?>

What i need is <?xml version="1.0" encoding="UTF-8"?>

Tried string manipulation to remove the '\' character with double quote but the value is not changing, what changes should i make? This is the whole code for creating the remaining nodes and all

  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");
Viveka Rj
  • 9
  • 3
  • 3
    Please provide [MCVE] that shows how do you get that result. It is *very* unlikely code in the post actually creates broken XML. Side note if you are looking at values in debugger that's totally different story but that's not what post says. – Alexei Levenkov Nov 23 '19 at 07:33
  • Code in the question produces exactly what post claims is expected (as expected): ` `. It is still unclear what exactly you have problem with. – Alexei Levenkov Nov 25 '19 at 19:11

0 Answers0