encoding/xml: No way of creating self terminating nodes with MarshalXML #6896
What steps will reproduce the problem? If possible, include a link to a program on play.golang.org. 1. http://play.golang.org/p/o20RjaRdtQ 2. 3. What is the expected output? It would be preferable to get <RPCElementTarget><running/></RPCElementTarget> What do you see instead? There is no way to do self terminating elements. The best we can do is to do a start and end element with no chardata. This does not work for my application. The closest output is: <RPCElementTarget><running></running></RPCElementTarget> Which compiler are you using (5g, 6g, 8g, gccgo)? 6g Which operating system are you using? OS X 10.9 Which version are you using? (run 'go version') go version go1.2 darwin/amd64 Please provide any additional information below.
The xml package does not handle this case at the moment. the XML rfc says that <element></element> and <element /> are semantically identical, but I understand that this is sometimes lost in the sea of interoperability. One solution to this problem would be to add an extra attribute to the struct tag to indicate that this tag should be encoded with the empty element form. If you want to tackle this, please remember to discuss your design before starting coding.
Labels changed: added release-none.
Status changed to Accepted.