marshalInterface marshals a Marshaler interface value.
(val Marshaler, start StartElement)
| 804 | |
| 805 | // marshalInterface marshals a Marshaler interface value. |
| 806 | func (p *printer) marshalInterface(val Marshaler, start StartElement) error { |
| 807 | // Push a marker onto the tag stack so that MarshalXML |
| 808 | // cannot close the XML tags that it did not open. |
| 809 | p.tags = append(p.tags, Name{}) |
| 810 | n := len(p.tags) |
| 811 | |
| 812 | err := val.MarshalXML(p.encoder, start) |
| 813 | if err != nil { |
| 814 | return err |
| 815 | } |
| 816 | |
| 817 | // Make sure MarshalXML closed all its tags. p.tags[n-1] is the mark. |
| 818 | if len(p.tags) > n { |
| 819 | return fmt.Errorf("xml: %s.MarshalXML wrote invalid XML: <%s> not closed", receiverType(val), p.tags[len(p.tags)-1].Local) |
| 820 | } |
| 821 | p.tags = p.tags[:n-1] |
| 822 | return nil |
| 823 | } |
| 824 | |
| 825 | // marshalTextInterface marshals a TextMarshaler interface value. |
| 826 | func (p *printer) marshalTextInterface(val encoding.TextMarshaler, start StartElement) error { |
no test coverage detected