Leave XML in a single line

Asked

Viewed 505 times

0

My c# application gets the idented xml. I need to leave this xml all in one line. How can I do this?

  • You must edit your question and add more details, describe what error message is being displayed and enter the code of what you tried to do , try to create a Minimum, Complete and Verifiable Example

  • thanks for the tips...

  • Your question is unclear. Try to score correctly so that it is possible to understand, and be more specific when explaining the problem, honestly I could not even understand right.

  • the solution is here: Solution Thank you

  • @Rookie, replicate the answer right here, in your question, already marking it as the answer. So some people who do not read English will be able to understand how to solve.

2 answers

1

If you get xml by a file:

XDocument document = XDocument.Load("arquivo.xml");
document.Save("arquivo2.xml", SaveOptions.DisableFormatting);

Or if you have xml in a string:

XDocument document = XDocument.Parse(stringXML);
document.Save("arquivo.xml", SaveOptions.DisableFormatting);

0

You can separate lines in array and then concaterate

string xml = dadosdoxml.ToString();

var separar = xml.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

string final = string.Join(" ", separar );
  • hasn’t worked out yet.... but thanks anyway

Browser other questions tagged

You are not signed in. Login or sign up in order to post.