Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(41)

Issue 4539082: code review 4539082: xml: add Marshal and MarshalIndent

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 11 months ago by kevlar
Modified:
13 years, 10 months ago
Reviewers:
rsc
CC:
rsc, golang-dev
Visibility:
Public.

Description

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).

Patch Set 1 #

Patch Set 2 : diff -r 2e64054a4cb2 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 2e64054a4cb2 https://go.googlecode.com/hg/ #

Total comments: 30

Patch Set 4 : diff -r 2e64054a4cb2 https://go.googlecode.com/hg/ #

Total comments: 18

Patch Set 5 : diff -r 3418f22c39eb https://go.googlecode.com/hg/ #

Total comments: 12

Patch Set 6 : diff -r 3418f22c39eb https://go.googlecode.com/hg/ #

Total comments: 19

Patch Set 7 : diff -r 3418f22c39eb https://go.googlecode.com/hg/ #

Patch Set 8 : diff -r 3418f22c39eb https://go.googlecode.com/hg/ #

Patch Set 9 : diff -r 3418f22c39eb https://go.googlecode.com/hg/ #

Total comments: 14

Patch Set 10 : diff -r cf0c2b126968 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+578 lines, -0 lines) Patch
M src/pkg/xml/Makefile View 1 1 chunk +1 line, -0 lines 0 comments Download
A src/pkg/xml/atom_test.go View 1 2 3 4 5 6 7 8 1 chunk +50 lines, -0 lines 0 comments Download
A src/pkg/xml/marshal.go View 1 2 3 4 5 6 7 8 9 1 chunk +228 lines, -0 lines 0 comments Download
A src/pkg/xml/marshal_test.go View 1 2 3 4 5 6 7 8 9 1 chunk +299 lines, -0 lines 0 comments Download

Messages

Total messages: 21
kevlar
Hello rsc@golang.org, golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 11 months ago (2011-05-25 00:14:31 UTC) #1
rsc
http://codereview.appspot.com/4539082/diff/7/src/pkg/xml/atom_test.go File src/pkg/xml/atom_test.go (right): http://codereview.appspot.com/4539082/diff/7/src/pkg/xml/atom_test.go#newcode6 src/pkg/xml/atom_test.go:6: var atom_value = &Feed{ no underscores; mixedCaps throughout see ...
13 years, 11 months ago (2011-05-25 03:12:58 UTC) #2
kevlar
PTAL Down to ~300 lines from ~450. If you do indeed think I should print ...
13 years, 11 months ago (2011-05-27 22:06:35 UTC) #3
kevlar
Ping
13 years, 11 months ago (2011-06-03 17:28:34 UTC) #4
rsc
http://codereview.appspot.com/4539082/diff/8001/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/8001/src/pkg/xml/marshal.go#newcode227 src/pkg/xml/marshal.go:227: // Skip zero values I still think this is ...
13 years, 11 months ago (2011-06-03 17:33:22 UTC) #5
rsc
http://codereview.appspot.com/4539082/diff/8001/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/8001/src/pkg/xml/marshal.go#newcode35 src/pkg/xml/marshal.go:35: type xmlPrinter struct { In package xml, it's redundant ...
13 years, 11 months ago (2011-06-03 17:43:54 UTC) #6
kevlar
PTAL http://codereview.appspot.com/4539082/diff/8001/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/8001/src/pkg/xml/marshal.go#newcode35 src/pkg/xml/marshal.go:35: type xmlPrinter struct { On 2011/06/03 17:43:54, rsc ...
13 years, 11 months ago (2011-06-03 18:37:56 UTC) #7
rsc
This is getting much simpler. Nice. http://codereview.appspot.com/4539082/diff/11002/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/11002/src/pkg/xml/marshal.go#newcode64 src/pkg/xml/marshal.go:64: func (p *printer) ...
13 years, 11 months ago (2011-06-03 18:53:53 UTC) #8
kevlar
PTAL http://codereview.appspot.com/4539082/diff/11002/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/11002/src/pkg/xml/marshal.go#newcode64 src/pkg/xml/marshal.go:64: func (p *printer) openTag(tag string, params []string) { ...
13 years, 11 months ago (2011-06-03 21:00:26 UTC) #9
rsc
http://codereview.appspot.com/4539082/diff/4003/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/4003/src/pkg/xml/marshal.go#newcode146 src/pkg/xml/marshal.go:146: p.WriteString(strconv.Quote(str)) On 2011/06/03 21:00:26, kevlar wrote: > Does this ...
13 years, 11 months ago (2011-06-03 21:21:12 UTC) #10
kevlar
http://codereview.appspot.com/4539082/diff/4003/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/4003/src/pkg/xml/marshal.go#newcode191 src/pkg/xml/marshal.go:191: name := strings.ToLower(ftyp.Name) On 2011/06/03 21:21:12, rsc wrote: > ...
13 years, 11 months ago (2011-06-03 21:37:13 UTC) #11
kevlar
PTAL http://codereview.appspot.com/4539082/diff/4003/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/4003/src/pkg/xml/marshal.go#newcode146 src/pkg/xml/marshal.go:146: p.WriteString(strconv.Quote(str)) On 2011/06/03 21:21:12, rsc wrote: > On ...
13 years, 11 months ago (2011-06-03 21:44:19 UTC) #12
rsc
> So you have to explicitly clear out innerxml if you don't want to > ...
13 years, 11 months ago (2011-06-03 21:51:13 UTC) #13
kevlar
PTAL Sorry this took so long; I made a silly mistake in fixing the case ...
13 years, 11 months ago (2011-06-03 22:44:25 UTC) #14
kevlar
I realized that I didn't have an innerxml test case (other than atom, but it's ...
13 years, 11 months ago (2011-06-07 20:16:48 UTC) #15
kevlar
ping
13 years, 10 months ago (2011-06-13 17:47:22 UTC) #16
rsc
Getting very close. http://codereview.appspot.com/4539082/diff/2003/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/2003/src/pkg/xml/marshal.go#newcode33 src/pkg/xml/marshal.go:33: // Marshal formats the given value ...
13 years, 10 months ago (2011-06-14 16:49:11 UTC) #17
kevlar
PTAL http://codereview.appspot.com/4539082/diff/2003/src/pkg/xml/marshal.go File src/pkg/xml/marshal.go (right): http://codereview.appspot.com/4539082/diff/2003/src/pkg/xml/marshal.go#newcode33 src/pkg/xml/marshal.go:33: // Marshal formats the given value as a ...
13 years, 10 months ago (2011-06-15 23:17:49 UTC) #18
kevlar
Ping
13 years, 10 months ago (2011-06-27 16:12:46 UTC) #19
rsc
LGTM
13 years, 10 months ago (2011-06-27 21:55:23 UTC) #20
rsc
13 years, 10 months ago (2011-06-27 23:07:30 UTC) #21
*** Submitted as http://code.google.com/p/go/source/detail?r=85fe786bbd63 ***

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
http://codereview.appspot.com/4539082

Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b