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

encode/xml: Support XML namespaces #6517

Closed
gopherbot opened this issue Sep 30, 2013 · 3 comments
Closed

encode/xml: Support XML namespaces #6517

gopherbot opened this issue Sep 30, 2013 · 3 comments

Comments

@gopherbot
Copy link
Contributor

by oltoko:

http://play.golang.org/p/J98usiO91P

If you look at this code you expect that Data of the "pers:on"-Tag is
unmarshaled into the Customer struct.
But if you run the code this doesn't happen, because there is a colon in the Tag-Name.
To prove that this code isn't wrong just remove the colon
or use this link:

http://play.golang.org/p/OyDM87mzVh
@davecheney
Copy link
Contributor

Comment 1:

colon is a reserved character in the XML spec[1], it denotes a namespace. The go XML
package does not handle namespaces so your example is equivalent to
http://play.golang.org/p/UbFjiHRhZt
[1] http://www.w3.org/TR/REC-xml/#NT-Name

@gopherbot
Copy link
Contributor Author

Comment 2 by oltoko:

Thank you for your answer. Sorry for the inconvenience because of this fault.
Are there any plans to improve the go XML package in the future to handle namespaces?

@rsc
Copy link
Contributor

rsc commented Oct 10, 2013

Comment 4:

XML name spaces are already supported.
golang.org/pkg/encoding/xml
"Package xml implements a simple XML 1.0 parser that understands XML name spaces."
However, your example at http://play.golang.org/p/J98usiO91P is not valid XML. In
<ns:tag>, the ns is not an absolute name. It is a relative reference to a URL
defined earlier in the XML. For example, these two stanzas are semantically equivalent
XML
<outer xmlns:pers="http://my.url/">
  <pers:on>Hello</pers:on>
</outer>
<outer xmlns:foo="http://my.url/">
  <foo:on>Hello</foo:on>
</outer>
A corrected version of the example is http://play.golang.org/p/lqxkM3MDeD.
If you must pass malformed XML to the parser, it will cope and assume that the "URL" is
the prefix itself, in which case you can do something like
http://play.golang.org/p/DXosg_tjfj. However, that is more fragile, because it does not
understand alternate encodings of the same XML (using different prefixes but the same
underlying URL) and I don't recommend it.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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