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

proposal: encoding/xml: Add RawMessage type #25683

Closed
OuSatoru opened this issue Jun 1, 2018 · 6 comments
Closed

proposal: encoding/xml: Add RawMessage type #25683

OuSatoru opened this issue Jun 1, 2018 · 6 comments

Comments

@OuSatoru
Copy link

OuSatoru commented Jun 1, 2018

Currently encoding/xml does not have a RawMessage type like encoding/json, this could be used like

type Info struct {
	XMLName xml.Name `xml:"ROOT"`
	A       string
	B       xml.RawMessage
}

func main() {
	a := `<?xml version="1.0" encoding="utf-8"?>
	<ROOT>
	<A>int</A>
	<B>123</B>
	</ROOT>`
	b := `<?xml version="1.0" encoding="utf-8"?>
	<ROOT>
	<A>string</A>
	<B>abcd</B>
	</ROOT>`
	var info Info
	xml.Unmarshal([]byte(a), &info)
	switch info.A {
	case "int":
		var i int
		xml.Unmarshal(info.B, &i)
		fmt.Println(info, i)
	case "string":
		var s string
		xml.Unmarshal(info.B, &s)
		fmt.Println(info, s)
	}
}

B could be some other struct.

@mvdan
Copy link
Member

mvdan commented Jun 1, 2018

What exactly is this issue about? It seems to me like people could declare json.RawMessage themselves and use it directly, without it needing to be part of encoding/json. So the same should apply to encoding/xml - you should be able to declare your own and use it.

Are you suggesting that encoding/xml.RawMessage be added to the standard library? Or are you asking for help on implementing XMLRawMessage yourself?

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 1, 2018
@OuSatoru
Copy link
Author

OuSatoru commented Jun 1, 2018

@mvdan Exactly I'm suggesting someone to add encoding/xml.RawMessage, but if I want to use it now, can I implement a simple version?

@mvdan
Copy link
Member

mvdan commented Jun 1, 2018

If you want to propose the addition of encoding/xml.RawMessage, you should use a proposal. See https://github.com/golang/proposal.

but if I want to use it now, can I implement a simple version?

Yes, as said above, I don't see why you wouldn't be able to declare that type yourself and use it.

@OuSatoru OuSatoru changed the title RawMessage for encoding/xml? proposal: encoding/xml: Add RawMessage type Jun 1, 2018
@gopherbot gopherbot added this to the Proposal milestone Jun 1, 2018
@OuSatoru
Copy link
Author

OuSatoru commented Jun 1, 2018

@mvdan edit it as a proposal

@ianlancetaylor ianlancetaylor removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 1, 2018
@kardianos
Copy link
Contributor

@rsc
Copy link
Contributor

rsc commented Jun 4, 2018

Like @mvdan says, you can implement this easily yourself. It doesn't need to be in encoding/xml. Also xml is effectively frozen until we have some more time to think about systemic issues in the API. Since this functionality does not require a change (it can be done outside the package), that's the best place for it.

@rsc rsc closed this as completed Jun 4, 2018
@golang golang locked and limited conversation to collaborators Jun 4, 2019
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

6 participants