Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/xml: Encoder duplicates namespace tags #7535
== What does 'go version' print? go version go1.2.1 darwin/amd64 == What steps reproduce the problem? http://play.golang.org/p/3_oUruPYhq == What happened? Encoder.EncodeToken duplicates namespace attributes. == What should have happened instead? The encoded document should have had a single namespace attribute. == Please provide any additional information below. Attribute names on an element must be unique; this is a well-formedness constraint per the XML 1.0 specification (http://www.w3.org/TR/xml/#uniqattspec). Per the specification, both validating and non-validating parsers must report well-formedness violations (http://www.w3.org/TR/xml/#sec-conformance). Encoding and decoding XML documents should be idempotent and produce equivalent documents. This issue means that not only that decoding and encoding the result produces a non-equivalent document, but that the document it generates is not-well-formed. This issue only occurs with namespaces. Normal attributes are handled correctly.
referenced this issue
Feb 24, 2015
I would expect Token to strip xmlns attributes: if you want them, use RawToken.
The change below does that and appears to fix both of the above examples:
The code base above also exposes the current set of namespace bindings on Decoder, which is generally more useful that having the xmlns attributes themselves (see #12406)
referenced this issue
Feb 19, 2016
I wanted to know if there is a work around for this yet (duplication of namespaces)?
I want to use a decoder/encoder combination with Token() to selectively reconstitute an XML document (.NET csproj format)
Creating and maintaining all the structs to demarshal into an object is not a suitable solution.
added a commit
May 4, 2017
I ran into this today for the first time (suprisingly).
I wouldn't mind working on this once some of my other XML patches are merged if a decision can be made on how to handle it. Would stripping xmlns attributes from
UPDATE: There appear to be tests that specifically check for this behavior, but I have no idea why as it seems categorically wrong. Maybe my naive understanding of XML is wrong (as it so often is)?
A tag prefix identifies the name space of the tag (https://www.w3.org/TR/xml/#sec-starttags)
Some logic was added to handle exceptions. The produced tag includes strings of attributes like
Only, explicit namespace and a colliding prefix can produce not well-formed XML because of attributes