Skip to content

Commit 66599c4

Browse files
committed
encoding/xml: remove Marshaler support
Marshaler has a number of open areas that need further thought (e.g. it doesn't handle attributes, it's supposed to handle tag names internally but has no information to do so, etc). We're removing it now and will bring it back with an interface that covers these aspects, after Go 1. Related to issue 2771, but doesn't fix it. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5574057
1 parent ddd67f2 commit 66599c4

File tree

2 files changed

+0
-33
lines changed

2 files changed

+0
-33
lines changed

src/pkg/encoding/xml/marshal.go

-20
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,8 @@ const (
2121
Header = `<?xml version="1.0" encoding="UTF-8"?>` + "\n"
2222
)
2323

24-
// A Marshaler can produce well-formatted XML representing its internal state.
25-
type Marshaler interface {
26-
MarshalXML() ([]byte, error)
27-
}
28-
2924
// Marshal returns the XML encoding of v.
3025
//
31-
// If v implements Marshaler, then Marshal calls its MarshalXML method.
32-
// Otherwise, Marshal uses the following procedure to create the XML.
33-
//
3426
// Marshal handles an array or slice by marshalling each of the elements.
3527
// Marshal handles a pointer by marshalling the value it points at or, if the
3628
// pointer is nil, by writing nothing. Marshal handles an interface value by
@@ -128,18 +120,6 @@ func (p *printer) marshalValue(val reflect.Value, finfo *fieldInfo) error {
128120
kind := val.Kind()
129121
typ := val.Type()
130122

131-
// Try Marshaler
132-
if typ.NumMethod() > 0 {
133-
if marshaler, ok := val.Interface().(Marshaler); ok {
134-
bytes, err := marshaler.MarshalXML()
135-
if err != nil {
136-
return err
137-
}
138-
p.Write(bytes)
139-
return nil
140-
}
141-
}
142-
143123
// Drill into pointers/interfaces
144124
if kind == reflect.Ptr || kind == reflect.Interface {
145125
if val.IsNil() {

src/pkg/encoding/xml/marshal_test.go

-13
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ type Ship struct {
3434
secret string
3535
}
3636

37-
type RawXML string
38-
39-
func (rx RawXML) MarshalXML() ([]byte, error) {
40-
return []byte(rx), nil
41-
}
42-
4337
type NamedType string
4438

4539
type Port struct {
@@ -298,13 +292,6 @@ var marshalTests = []struct {
298292
UnmarshalOnly: true,
299293
},
300294

301-
// Test marshaller interface
302-
{
303-
Value: RawXML("</>"),
304-
ExpectXML: `</>`,
305-
MarshalOnly: true,
306-
},
307-
308295
// Test structs
309296
{Value: &Port{Type: "ssl", Number: "443"}, ExpectXML: `<port type="ssl">443</port>`},
310297
{Value: &Port{Number: "443"}, ExpectXML: `<port>443</port>`},

0 commit comments

Comments
 (0)