XMLDocument.Save adds return carriages to XML when elements are blank

后端 未结 3 1340
刺人心
刺人心 2021-01-08 01:43

I\'m loading a XML Document that has some tags that have no innertext.

If I populate the innertext with some data then it works as needed (you get opening tag, inner

3条回答
  •  臣服心动
    2021-01-08 01:50

    This fixed it for me...

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(@"C:\test.xml");
    
    //Save the xml and then cleanup
    XmlWriterSettings settings = new XmlWriterSettings { Indent = true };
    XmlWriter writer = XmlWriter.Create(@"C:\test.xml", settings);
    xmlDoc.Save(writer);
    

提交回复
热议问题