Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: allow Marshal to use CDATA #12963

Closed
ghost opened this issue Oct 16, 2015 · 4 comments
Closed

encoding/xml: allow Marshal to use CDATA #12963

ghost opened this issue Oct 16, 2015 · 4 comments
Milestone

Comments

@ghost
Copy link

ghost commented Oct 16, 2015

My team is interested in generating VAST 3 (video ad standard template) XML using the xml package. Unfortunately the VAST 3 spec specifies:

" All URIs or any other free text fields containing potentially dangerous characters contained in the VAST document should be wrapped in CDATA blocks." http://www.iab.net/media/file/VASTv3.0.pdf p. 23

Currently fields labeled with the xml ",chardata" tag are only output as URL encoded XML. We have a workaround using the Marshaler interface, but it's verbose and bug prone. i.e:

// CharData is a string that should be cdata-wrapped according to the VAST 3 spec.
type CharData string

// MarshalXML implements the xml.Marshaler interface for generating XML.
func (cd CharData) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
    return e.EncodeElement(struct {
        S string `xml:",innerxml"`
    }{
        S: "<![CDATA[" + string(cd) + "]]>",
    }, start)
}

There should be a first-class way to output CDATA escaped data in the xml package, perhaps with the addition of a ",cdata" tag.

@rsc rsc added this to the Go1.6 milestone Oct 16, 2015
@gopherbot
Copy link

CL https://golang.org/cl/16047 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Oct 23, 2015

As far as addressing VAST 3 is concerned, does it make more sense to have a ,cdata field or to have a method call on *xml.Encoder that says "use CDATA always"?

@rsc rsc changed the title encoding/xml: Add CDATA-wrapper support to xml.Marshal encoding/xml: allow Marshal to use CDATA Nov 5, 2015
@rsc rsc closed this as completed in 3f6b91b Nov 25, 2015
@gopherbot
Copy link

CL https://golang.org/cl/17232 mentions this issue.

rsc added a commit that referenced this issue Dec 3, 2015
Followup to CL 16047.
For #12963.

Change-Id: I596cd5109b25a4079b966427411860fde8b9b54a
Reviewed-on: https://go-review.googlesource.com/17232
Reviewed-by: David Crawshaw <crawshaw@golang.org>
@akrylysov
Copy link

It would be nice if it was a way to put a cdata content into a nested node: allow tags like xml:"a,cdata", xml:"a>b>c,cdata".

@golang golang locked and limited conversation to collaborators Jun 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants