Skip to content

proposal: encoding/xml: add RawXML token #26756

Open
@SamWhited

Description

@SamWhited

I have recently been experimenting with writing an XML encoder that (given a struct or other similar type) emits xml.Token's instead of bytes. In doing so I discovered that some XML could be encoded using structs that cannot currently be encoded using the "Encoder".EncodeToken method and that I couldn't finish my project without occasionally switching over to the struct based API. There is currently no equivalent in the SAX-like API for the ,innerxml tag on struct fields. This is useful as it both lets us encode invalid XML (which is unfortunately quite common, and it may be desirable to let Go's encoder work with broken XML encoders and decoders in the wild), and lets us encode pre-escaped XML without accidentally double-escaping (eg. if we know we already have valid XML such as & we can prevent it from being turned into &).
This is similar in spirit to the known safe types in the html/template package (eg. HTML or JS).

Proposal: https://golang.org/design/26756-rawxml-token

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions