unmarshalTextInterface unmarshals a single XML element into val. The chardata contained in the element (but not its children) is passed to the text unmarshaler.
(val encoding.TextUnmarshaler)
| 226 | // The chardata contained in the element (but not its children) |
| 227 | // is passed to the text unmarshaler. |
| 228 | func (d *Decoder) unmarshalTextInterface(val encoding.TextUnmarshaler) error { |
| 229 | var buf []byte |
| 230 | depth := 1 |
| 231 | for depth > 0 { |
| 232 | t, err := d.Token() |
| 233 | if err != nil { |
| 234 | return err |
| 235 | } |
| 236 | switch t := t.(type) { |
| 237 | case CharData: |
| 238 | if depth == 1 { |
| 239 | buf = append(buf, t...) |
| 240 | } |
| 241 | case StartElement: |
| 242 | depth++ |
| 243 | case EndElement: |
| 244 | depth-- |
| 245 | } |
| 246 | } |
| 247 | return val.UnmarshalText(buf) |
| 248 | } |
| 249 | |
| 250 | // unmarshalAttr unmarshals a single XML attribute into val. |
| 251 | func (d *Decoder) unmarshalAttr(val reflect.Value, attr Attr) error { |