c# - Omit XML declaration? -


I have an XElement that I need to parse to remove white space in the closing tag. My code looks like this:

  var stringBuilder = new StringBuilder (); (Var String Vibrator = Using New String Vibrator) {xelement.Save (stringWriter); } StringBuilder.Replace ("/>", "/>"); Var xml = stringBuilder.ToString ();  

Actually, I am making a string manufacturer and am changing the unnecessary white space. The resulting string looks fine, in addition it contains the XML declaration. I know that on an XMLroller, I can leave the declaration with OmitXmlDeclaration , but StringWriter does not have this.

Is there any way to do this, or do I need to do manually, understand the result from string resulting?

For clarity, here & # 39; s before and after XML:

  // first & lt; Actionitem actiontaken = "none" target = "0" without target = "0"> & Lt; Airways & gt; Popup window & lt; / Windowname & gt; & Lt; Windowposx & gt; -1 & lt; / Windowposx> & Lt; Windowposy & gt; -1 & lt; / Windowposy & gt; & Lt; Windowwidth & gt; -1 & lt; / Windowwidth & gt; & Lt; Windowheight & gt; -1 & lt; / Windowheight & gt; & Lt; Noscrollbars & gt; False & lt; / Noscrollbars & gt; & Lt; Nomenubar / & gt; & Lt; Notoolbar / & gt; & Lt; Notices /> & Lt; Nostatus / & gt; & Lt; Nolocation / & gt; & Lt; Browser Window / & gt; & Lt; / Actionitem & gt; // followed by & lt ;? XML version = "1.0" encoding = "UTF-16"? & Gt; & Lt; Actionem Action Technique = "none" target = "0" target = 1 = "0" & ​​gt; & Lt; Airways & gt; Popup window & lt; / Windowname & gt; & Lt; Windowposx & gt; -1 & lt; / Windowposx> & Lt; Windowposy & gt; -1 & lt; / Windowposy & gt; & Lt; Windowwidth & gt; -1 & lt; / Windowwidth & gt; & Lt; Windowheight & gt; -1 & lt; / Windowheight & gt; & Lt; Noscrollbars & gt; False & lt; / Noscrollbars & gt; & Lt; Nomenubar / & gt; & Lt; Notoolbar / & gt; & Lt; Noresize / & gt; & Lt; Nostatus / & gt; & Lt; Nolocation / & gt; & Lt; BrowserWND / & gt; & Lt; / Actionitem & gt;  

Edit: For those people who have been asked, this defense project is for the department, their specifications have been closed. This means that there is no white space in the closing tag, no matter how much I protest. Whether correct or not, they do not want it, and they are signing the paycheck. I just try to adjust them.

Use to save instead of / Code>. It also eliminates the need for stringbuilder

  string xml = xelement.ToString (); // Added a declaration element xml = xml.Replace ("/>", "/>"); // If you really think you want  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -