How to remove whitespace from an XmlDocument

前端 未结 2 667
-上瘾入骨i
-上瘾入骨i 2020-12-06 13:38

I have an XML document from which I want to remove white spaces and carriage returns. How can I get the modified XML using C#.

2条回答
  •  天命终不由人
    2020-12-06 14:27

    Set the preserveWhitespace flag to false:

    XmlDocument doc = new XmlDocument();
    doc.PreserveWhitespace = false;
    doc.Load("foo.xml");
    // doc.InnerXml contains no spaces or returns
    

提交回复
热议问题