]> Cypherpunks repositories - gostls13.git/commit
xml: add Marshal and MarshalIndent
authorKyle Lemons <kyle@kylelemons.net>
Mon, 27 Jun 2011 23:07:28 +0000 (19:07 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 27 Jun 2011 23:07:28 +0000 (19:07 -0400)
commitabd50de296c129bbb4def693a6f1ebb66d6221f6
tree6609a16011c8e4afed9f82934c292b00c8cfc120
parent9ded2b34516fa30ee7e79255ca8eeb5572364c19
xml: add Marshal and MarshalIndent

I have written up a Marshal and MarshalIndent pair that should
closely reflect the way that Unmarshal works.  I would love feedback
on making this code more accessible and efficient... I haven't used
reflecton on this scale before, so there is probably a lot of work
that can be done on that.

Some potentially controversial things:
- All tag names are lower-cased by default.
- Zero-valued struct values are skipped.
- No namespace prefix (o:tag, etc) mechanism is supplied.
- You are allowed to marshal non-struct values (even though unmarshal
  cannot handle them).
- A tag for a non-XMLName struct field that isn't "attr", "chardata",
  or "innerxml" is used as the name of the tag.  This could wreak
  havoc if you try to marshal a protobuf struct.
- The "innerxml" and "chardata" are inserted verbatim.  If you try to
  marshal something straight from unmarshal, the results could be
  unexpected (remove "innerxml" support from Marshal would be one
  possible solution).

R=rsc
CC=golang-dev
https://golang.org/cl/4539082
src/pkg/xml/Makefile
src/pkg/xml/atom_test.go [new file with mode: 0644]
src/pkg/xml/marshal.go [new file with mode: 0644]
src/pkg/xml/marshal_test.go [new file with mode: 0644]