I'm writing a method that is generating the body of an XML file. The method returns a string, which I then pass to
const file = new Blob([content], {type: "text/xml"});
as the content variable. How can I get this string to format itself as a more readable format? Specifically, I'm looking for a way to auto-indent and add newlines wherever necessary as opposed to adding them manually.
Asked
Active
Viewed 30 times
0

Andrew McAvoy
- 1
- 1
-
https://stackoverflow.com/questions/65547725/how-to-format-an-xml-string-with-line-breaks-using-javascript – PM 77-1 Jun 22 '22 at 19:56
-
@PM77-1 that only works if there isn't any content between the tags, and my string has data between the tags – Andrew McAvoy Jun 22 '22 at 19:59
-
How about https://stackoverflow.com/questions/376373/pretty-printing-xml-with-javascript then? Anything there fit your needs? – PM 77-1 Jun 22 '22 at 20:05