marshalInterface marshals a Marshaler interface value.
(val Marshaler, start StartElement)
| 678 | |
| 679 | // marshalInterface marshals a Marshaler interface value. |
| 680 | func (p *printer) marshalInterface(val Marshaler, start StartElement) error { |
| 681 | // Push a marker onto the tag stack so that MarshalXML |
| 682 | // cannot close the XML tags that it did not open. |
| 683 | p.tags = append(p.tags, Name{}) |
| 684 | n := len(p.tags) |
| 685 | |
| 686 | err := val.MarshalXML(p.encoder, start) |
| 687 | if err != nil { |
| 688 | return err |
| 689 | } |
| 690 | |
| 691 | // Make sure MarshalXML closed all its tags. p.tags[n-1] is the mark. |
| 692 | if len(p.tags) > n { |
| 693 | return fmt.Errorf("xml: %s.MarshalXML wrote invalid XML: <%s> not closed", receiverType(val), p.tags[len(p.tags)-1].Local) |
| 694 | } |
| 695 | p.tags = p.tags[:n-1] |
| 696 | return nil |
| 697 | } |
| 698 | |
| 699 | // marshalTextInterface marshals a TextMarshaler interface value. |
| 700 | func (p *printer) marshalTextInterface(val encoding.TextMarshaler, start StartElement) error { |
no test coverage detected