Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7.  
  8. // Compile and run via the command line:
  9. // > XmlFormatter.exe < BadXml.xml > GoodXml.xml
  10. // If GoodXml is ignored, it will print to stdout.
  11.  
  12. namespace XmlFormatter {
  13. class Program {
  14. static void Main(string[] args) {
  15. var tr = Console.In;
  16. string s = tr.ReadToEnd();
  17. XmlDocument doc = new XmlDocument();
  18. try {
  19. doc.LoadXml(s);
  20. StringBuilder sb = new StringBuilder();
  21. using (XmlTextWriter tw = new XmlTextWriter(new StringWriter(sb))) {
  22. tw.Formatting = Formatting.Indented;
  23. doc.Save(tw);
  24. }
  25. Console.Write(sb.ToString());
  26. } catch (XmlException ex) {
  27. Console.WriteLine("There was an error reading the XML file. Please make sure it is an actual XML file. " + ex.Message);
  28. }
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment