On Friday, November 4, 2016 at 2:32:24 PM UTC-7, Tong Sun wrote:
>
> How to beautify a given XML string in GO? 
>

As someone who has spent a fair amount of time in the complexities of XML, 
it is worth noting that XML is not equivalent to JSON in the context of 
your question.

Only with a schema or a DTD for the XML instance in question can you be 
certain of whether or not white-space is significant.

There's also considerations like canonicalization and normalization, which 
also don't apply to JSON.

When generating XML from a data structure, you can already know where the 
data structure would ignore white-space. So it would be possible to 
generate "beautiful" XML in that context, but it has to be done as part of 
the generation. The beautification cannot be done *safely* by some tool 
after-the-fact, at least not without much further context (schemas, DTDs, 
etc.), or without assumptions by the user of such an API.


> The xml.MarshalIndent() only apply to a GO structure, not XML strings. 
>

Yes. See my points above.

Eric.

-- 
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