How to place xml on one line in c # code?

How to place xml on one line in c # code?

Before:

<CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> </CATALOG> 

After:

 <CATALOG><CD><TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST>COUNTRY>USA</COUNTRY>.... 
+6
source share
4 answers

Assuming you can use LINQ to XML, and XML is currently in the file:

 XDocument document = XDocument.Load("test.xml"); document.Save("test2.xml", SaveOptions.DisableFormatting); 
+11
source

If you have XML in line:

 xml.Replace("\n", "").Replace("\r", "") 
+5
source

If you cannot use LINQ to XML, you can:

 XmlDocument xmlDoc = new XmlDocument() xmlDoc.LoadXml("Xml as string"); or xmlDoc.Load(filepath) xmlDoc.InnerXml -- this should return one liner 
+3
source

I know this is an old question, but it helped me find XDocument.ToString ()

 XDocument doc = XDocument.Load("file.xml"); // Flat one line XML string s = doc.ToString(SaveOptions.DisableFormatting); 

Check Document SaveOptions

0
source

Source: https://habr.com/ru/post/885600/


All Articles