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: support for xml:lang attribute #14358

Open
pdw-mb opened this issue Feb 17, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@pdw-mb
Copy link

commented Feb 17, 2016

xml:lang is a standard attribute defined by the XML specification. Using it is complicated by the fact that an element inherits the nearest xml:lang declaration on itself or an ancestor. For example:

  <document>
    <foo xml:lang="en-GB">
      <bar>This is in en-GB</bar>
   </foo>
 </document>

The element bar has an effective xml:lang value of "en-GB".

At the moment, an application wanting access to this information would need to consume an XML document token by token, and maintain its own stack of xml:lang attributes (or include an xml:lang attribute on all parent structs being unmarshalled, and process those). It would be nice if Decoder maintained this stack itself, and exposed it to structs being unmarshaled so that you could easily get the current effective xml:lang attribute.

There is code to do the above here:

https://code.blinkace.com/go/xml/commit/6dbed72bf9bec281c053aee80af76ac542a395c9

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Feb 17, 2016

@ianlancetaylor ianlancetaylor changed the title encoding/xml - support for xml:lang attribute encoding/xml: support for xml:lang attribute Feb 17, 2016

@BenLubar

This comment has been minimized.

Copy link

commented Apr 30, 2018

Just naming the field xml:lang works for marshaling but not for unmarshaling currently:

https://play.golang.org/p/DC3py653Zcb

@BenLubar

This comment has been minimized.

Copy link

commented Apr 30, 2018

Ah, giving it the implicitly-defined namespace URL works completely:

https://play.golang.org/p/b3h-nedvurN

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