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: struct tag "a>b>c" not valid on XMLName fields #35676

bemasher opened this issue Nov 18, 2019 · 2 comments

encoding/xml: struct tag "a>b>c" not valid on XMLName fields #35676

bemasher opened this issue Nov 18, 2019 · 2 comments


Copy link

@bemasher bemasher commented Nov 18, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.4 windows/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

package main

import (

type NestedField struct {
	Field string `xml:"a>b>c"`

type NestedNameStructTag struct {
	XMLName xml.Name `xml:"a>b>c"`

type NestedNameValue struct {
	XMLName xml.Name

func main() {
	nf := NestedField{}
	xmlBytes, _ := xml.MarshalIndent(nf, "", "    ")


	nnst := NestedNameStructTag{}
	xmlBytes, _ = xml.MarshalIndent(nnst, "", "    ")


	nnv := NestedNameValue{XMLName: xml.Name{Local: "a>b>c"}}
	xmlBytes, _ = xml.MarshalIndent(nnv, "", "    ")





What did you expect to see?

Nested struct tags on XMLName fields should produce nested elements as shown in the "NestedField" example above.

Unless I've missed an exception in the documentation, this is what I expected.

What did you see instead?

The element name used the provided struct tag verbatim without escaping invalid characters or nesting elements as expected.

I think it's probably reasonable for marshal to behave this way, but the documentation should be updated to match.

Related issue:

#2119 encoding/xml: Marshal doesn't understand "parent>child" struct tags

Copy link

@toothrot toothrot commented Nov 18, 2019

I agree that the behavior seems reasonable, and updating the documentation to mention that Name.Local is used verbatim seems helpful.

/cc @rsc who owns encoding/xml

Copy link

@gopherbot gopherbot commented Nov 20, 2019

Change mentions this issue: encoding/xml: clarify doc on XMLName and field tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.