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: did not see expected CDATA #14798

Closed
ckeyer opened this Issue Mar 13, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@ckeyer
Copy link

ckeyer commented Mar 13, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
$ go version
go version go1.6 darwin/amd64
  1. What operating system and processor architecture are you using (go env)?
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/***"
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="0"
  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.

http://play.golang.org/p/23xH1pmJuv

  1. What did you expect to see?
<Response><KKName><![CDATA[ something bulabula ]]></KKName><Age>12</Age></Response>

https://golang.org/pkg/encoding/xml/#Marshal

  1. What did you see instead?
<Response><KKName>something bulabula</KKName><Age>12</Age></Response>

@ianlancetaylor ianlancetaylor changed the title about xml cdata encoding/xml: did not see expected CDATA Mar 14, 2016

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Mar 14, 2016

When I run your program using Go 1.6, I get

xml: invalid tag in field Name of type main.Response: "KKName,cdata"

I do get your reported results with Go 1.5. The problem is that a cdata element is not an XML element, and therefore should not have a name.

One way to get what you want is http://play.golang.org/p/-DVeAjptj5 .

Please take any questions about this to a forum; see https://golang.org/wiki/Questions. Thanks.

@ckeyer

This comment has been minimized.

Copy link
Author

ckeyer commented Mar 14, 2016

@ianlancetaylor Thanks.

@ckeyer

This comment has been minimized.

Copy link
Author

ckeyer commented Mar 14, 2016

@ianlancetaylor How to set the name of the outermost xml? like

<xml><KKName><![CDATA[namewang]]></KKName><Age>12</Age></xml>
@bradfitz

This comment has been minimized.

Copy link
Member

bradfitz commented Mar 14, 2016

Please take any questions about this to a forum; see https://golang.org/wiki/Questions. Thanks.

@ckeyer

This comment has been minimized.

Copy link
Author

ckeyer commented Mar 14, 2016

🆗

@golang golang locked and limited conversation to collaborators Mar 14, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.