@@ -192,19 +192,19 @@ func receiverType(val interface{}) string {
192
192
193
193
// unmarshalInterface unmarshals a single XML element into val.
194
194
// start is the opening tag of the element.
195
- func (p * Decoder ) unmarshalInterface (val Unmarshaler , start * StartElement ) error {
195
+ func (d * Decoder ) unmarshalInterface (val Unmarshaler , start * StartElement ) error {
196
196
// Record that decoder must stop at end tag corresponding to start.
197
- p .pushEOF ()
197
+ d .pushEOF ()
198
198
199
- p .unmarshalDepth ++
200
- err := val .UnmarshalXML (p , * start )
201
- p .unmarshalDepth --
199
+ d .unmarshalDepth ++
200
+ err := val .UnmarshalXML (d , * start )
201
+ d .unmarshalDepth --
202
202
if err != nil {
203
- p .popEOF ()
203
+ d .popEOF ()
204
204
return err
205
205
}
206
206
207
- if ! p .popEOF () {
207
+ if ! d .popEOF () {
208
208
return fmt .Errorf ("xml: %s.UnmarshalXML did not consume entire <%s> element" , receiverType (val ), start .Name .Local )
209
209
}
210
210
@@ -214,11 +214,11 @@ func (p *Decoder) unmarshalInterface(val Unmarshaler, start *StartElement) error
214
214
// unmarshalTextInterface unmarshals a single XML element into val.
215
215
// The chardata contained in the element (but not its children)
216
216
// is passed to the text unmarshaler.
217
- func (p * Decoder ) unmarshalTextInterface (val encoding.TextUnmarshaler ) error {
217
+ func (d * Decoder ) unmarshalTextInterface (val encoding.TextUnmarshaler ) error {
218
218
var buf []byte
219
219
depth := 1
220
220
for depth > 0 {
221
- t , err := p .Token ()
221
+ t , err := d .Token ()
222
222
if err != nil {
223
223
return err
224
224
}
@@ -237,7 +237,7 @@ func (p *Decoder) unmarshalTextInterface(val encoding.TextUnmarshaler) error {
237
237
}
238
238
239
239
// unmarshalAttr unmarshals a single XML attribute into val.
240
- func (p * Decoder ) unmarshalAttr (val reflect.Value , attr Attr ) error {
240
+ func (d * Decoder ) unmarshalAttr (val reflect.Value , attr Attr ) error {
241
241
if val .Kind () == reflect .Ptr {
242
242
if val .IsNil () {
243
243
val .Set (reflect .New (val .Type ().Elem ()))
@@ -276,7 +276,7 @@ func (p *Decoder) unmarshalAttr(val reflect.Value, attr Attr) error {
276
276
val .Set (reflect .Append (val , reflect .Zero (val .Type ().Elem ())))
277
277
278
278
// Recur to read element into slice.
279
- if err := p .unmarshalAttr (val .Index (n ), attr ); err != nil {
279
+ if err := d .unmarshalAttr (val .Index (n ), attr ); err != nil {
280
280
val .SetLen (n )
281
281
return err
282
282
}
@@ -299,11 +299,11 @@ var (
299
299
)
300
300
301
301
// Unmarshal a single XML element into val.
302
- func (p * Decoder ) unmarshal (val reflect.Value , start * StartElement ) error {
302
+ func (d * Decoder ) unmarshal (val reflect.Value , start * StartElement ) error {
303
303
// Find start element if we need it.
304
304
if start == nil {
305
305
for {
306
- tok , err := p .Token ()
306
+ tok , err := d .Token ()
307
307
if err != nil {
308
308
return err
309
309
}
@@ -333,24 +333,24 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error {
333
333
if val .CanInterface () && val .Type ().Implements (unmarshalerType ) {
334
334
// This is an unmarshaler with a non-pointer receiver,
335
335
// so it's likely to be incorrect, but we do what we're told.
336
- return p .unmarshalInterface (val .Interface ().(Unmarshaler ), start )
336
+ return d .unmarshalInterface (val .Interface ().(Unmarshaler ), start )
337
337
}
338
338
339
339
if val .CanAddr () {
340
340
pv := val .Addr ()
341
341
if pv .CanInterface () && pv .Type ().Implements (unmarshalerType ) {
342
- return p .unmarshalInterface (pv .Interface ().(Unmarshaler ), start )
342
+ return d .unmarshalInterface (pv .Interface ().(Unmarshaler ), start )
343
343
}
344
344
}
345
345
346
346
if val .CanInterface () && val .Type ().Implements (textUnmarshalerType ) {
347
- return p .unmarshalTextInterface (val .Interface ().(encoding.TextUnmarshaler ))
347
+ return d .unmarshalTextInterface (val .Interface ().(encoding.TextUnmarshaler ))
348
348
}
349
349
350
350
if val .CanAddr () {
351
351
pv := val .Addr ()
352
352
if pv .CanInterface () && pv .Type ().Implements (textUnmarshalerType ) {
353
- return p .unmarshalTextInterface (pv .Interface ().(encoding.TextUnmarshaler ))
353
+ return d .unmarshalTextInterface (pv .Interface ().(encoding.TextUnmarshaler ))
354
354
}
355
355
}
356
356
@@ -376,7 +376,7 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error {
376
376
// TODO: For now, simply ignore the field. In the near
377
377
// future we may choose to unmarshal the start
378
378
// element on it, if not nil.
379
- return p .Skip ()
379
+ return d .Skip ()
380
380
381
381
case reflect .Slice :
382
382
typ := v .Type ()
@@ -392,7 +392,7 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error {
392
392
v .Set (reflect .Append (val , reflect .Zero (v .Type ().Elem ())))
393
393
394
394
// Recur to read element into slice.
395
- if err := p .unmarshal (v .Index (n ), start ); err != nil {
395
+ if err := d .unmarshal (v .Index (n ), start ); err != nil {
396
396
v .SetLen (n )
397
397
return err
398
398
}
@@ -445,7 +445,7 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error {
445
445
case fAttr :
446
446
strv := finfo .value (sv )
447
447
if a .Name .Local == finfo .name && (finfo .xmlns == "" || finfo .xmlns == a .Name .Space ) {
448
- if err := p .unmarshalAttr (strv , a ); err != nil {
448
+ if err := d .unmarshalAttr (strv , a ); err != nil {
449
449
return err
450
450
}
451
451
handled = true
@@ -460,7 +460,7 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error {
460
460
if ! handled && any >= 0 {
461
461
finfo := & tinfo .fields [any ]
462
462
strv := finfo .value (sv )
463
- if err := p .unmarshalAttr (strv , a ); err != nil {
463
+ if err := d .unmarshalAttr (strv , a ); err != nil {
464
464
return err
465
465
}
466
466
}
@@ -488,11 +488,11 @@ func (p *Decoder) unmarshal(val reflect.Value, start *StartElement) error {
488
488
case fInnerXml :
489
489
if ! saveXML .IsValid () {
490
490
saveXML = finfo .value (sv )
491
- if p .saved == nil {
491
+ if d .saved == nil {
492
492
saveXMLIndex = 0
493
- p .saved = new (bytes.Buffer )
493
+ d .saved = new (bytes.Buffer )
494
494
} else {
495
- saveXMLIndex = p .savedOffset ()
495
+ saveXMLIndex = d .savedOffset ()
496
496
}
497
497
}
498
498
}
@@ -505,38 +505,38 @@ Loop:
505
505
for {
506
506
var savedOffset int
507
507
if saveXML .IsValid () {
508
- savedOffset = p .savedOffset ()
508
+ savedOffset = d .savedOffset ()
509
509
}
510
- tok , err := p .Token ()
510
+ tok , err := d .Token ()
511
511
if err != nil {
512
512
return err
513
513
}
514
514
switch t := tok .(type ) {
515
515
case StartElement :
516
516
consumed := false
517
517
if sv .IsValid () {
518
- consumed , err = p .unmarshalPath (tinfo , sv , nil , & t )
518
+ consumed , err = d .unmarshalPath (tinfo , sv , nil , & t )
519
519
if err != nil {
520
520
return err
521
521
}
522
522
if ! consumed && saveAny .IsValid () {
523
523
consumed = true
524
- if err := p .unmarshal (saveAny , & t ); err != nil {
524
+ if err := d .unmarshal (saveAny , & t ); err != nil {
525
525
return err
526
526
}
527
527
}
528
528
}
529
529
if ! consumed {
530
- if err := p .Skip (); err != nil {
530
+ if err := d .Skip (); err != nil {
531
531
return err
532
532
}
533
533
}
534
534
535
535
case EndElement :
536
536
if saveXML .IsValid () {
537
- saveXMLData = p .saved .Bytes ()[saveXMLIndex :savedOffset ]
537
+ saveXMLData = d .saved .Bytes ()[saveXMLIndex :savedOffset ]
538
538
if saveXMLIndex == 0 {
539
- p .saved = nil
539
+ d .saved = nil
540
540
}
541
541
}
542
542
break Loop
@@ -666,7 +666,7 @@ func copyValue(dst reflect.Value, src []byte) (err error) {
666
666
// The consumed result tells whether XML elements have been consumed
667
667
// from the Decoder until start's matching end element, or if it's
668
668
// still untouched because start is uninteresting for sv's fields.
669
- func (p * Decoder ) unmarshalPath (tinfo * typeInfo , sv reflect.Value , parents []string , start * StartElement ) (consumed bool , err error ) {
669
+ func (d * Decoder ) unmarshalPath (tinfo * typeInfo , sv reflect.Value , parents []string , start * StartElement ) (consumed bool , err error ) {
670
670
recurse := false
671
671
Loop:
672
672
for i := range tinfo .fields {
@@ -681,7 +681,7 @@ Loop:
681
681
}
682
682
if len (finfo .parents ) == len (parents ) && finfo .name == start .Name .Local {
683
683
// It's a perfect match, unmarshal the field.
684
- return true , p .unmarshal (finfo .value (sv ), start )
684
+ return true , d .unmarshal (finfo .value (sv ), start )
685
685
}
686
686
if len (finfo .parents ) > len (parents ) && finfo .parents [len (parents )] == start .Name .Local {
687
687
// It's a prefix for the field. Break and recurse
@@ -704,18 +704,18 @@ Loop:
704
704
// prefix. Recurse and attempt to match these.
705
705
for {
706
706
var tok Token
707
- tok , err = p .Token ()
707
+ tok , err = d .Token ()
708
708
if err != nil {
709
709
return true , err
710
710
}
711
711
switch t := tok .(type ) {
712
712
case StartElement :
713
- consumed2 , err := p .unmarshalPath (tinfo , sv , parents , & t )
713
+ consumed2 , err := d .unmarshalPath (tinfo , sv , parents , & t )
714
714
if err != nil {
715
715
return true , err
716
716
}
717
717
if ! consumed2 {
718
- if err := p .Skip (); err != nil {
718
+ if err := d .Skip (); err != nil {
719
719
return true , err
720
720
}
721
721
}
0 commit comments