One thing to consider is what level of change to the file is acceptable? If 
it is just to be human read, than the suggestions already given may do what 
you want; but it you want to take that result and preserve it for future 
use, then the mxj and the encoding/xml based methods may produce unwanted 
alterations, in which case a package 
like https://github.com/go-xmlfmt/xmlfmt , which doesn't actually parse the 
xml properly at all, just tries to push it back and forth to line up and 
look pretty using regular expressions might be more to your taste. As far 
as I can see, it won't change anything other than whitespace, where a 
parse/pretty-print cycle may have effects such as replicating namespace 
entries or prefixes throughout, changing self-closing tags to tag-pairs or 
vice-versa, etc.

Regexps are pretty cringe-worthy when you see them being used in code that 
is trying to parse HTML or XML and operate on it, but for this use-case, 
they might handle pretty-printing potentially invalid XML data more readily 
than a parser. I.e. the regexp is not going to care if the xml file you got 
has unbalanced tags, etc, and will probably nicely format the first half of 
an XML file that got the latter half replaced with garbage from 
cross-linking or the like.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to