MCPcopy Create free account
hub / github.com/aws/smithy-go / Value

Method Value

encoding/xml/xml_decoder.go:106–138  ·  view source on GitHub ↗

Value provides an abstraction to retrieve char data value within an xml element. The method will return an error if it encounters a nested xml element instead of char data. This method should only be used to retrieve simple type or blob shape values as []byte.

()

Source from the content-addressed store, hash-verified

104// The method will return an error if it encounters a nested xml element instead of char data.
105// This method should only be used to retrieve simple type or blob shape values as []byte.
106func (d NodeDecoder) Value() (c []byte, err error) {
107 t, e := d.Decoder.Token()
108 if e != nil {
109 return c, e
110 }
111
112 endElement := d.StartEl.End()
113
114 switch ev := t.(type) {
115 case xml.CharData:
116 c = ev.Copy()
117 case xml.EndElement: // end tag or self-closing
118 if ev == endElement {
119 return []byte{}, err
120 }
121 return c, fmt.Errorf("expected value for %v element, got %T type %v instead", d.StartEl.Name.Local, t, t)
122 default:
123 return c, fmt.Errorf("expected value for %v element, got %T type %v instead", d.StartEl.Name.Local, t, t)
124 }
125
126 t, e = d.Decoder.Token()
127 if e != nil {
128 return c, e
129 }
130
131 if ev, ok := t.(xml.EndElement); ok {
132 if ev == endElement {
133 return c, err
134 }
135 }
136
137 return c, fmt.Errorf("expected end element %v, got %T type %v instead", endElement, t, t)
138}
139
140// FetchRootElement takes in a decoder and returns the first start element within the xml body.
141// This function is useful in fetching the start element of an XML response and ignore the

Callers 1

TestXMLNodeDecoder_ValueFunction · 0.45

Calls 4

TokenMethod · 0.80
ErrorfMethod · 0.80
EndMethod · 0.65
CopyMethod · 0.45

Tested by 1

TestXMLNodeDecoder_ValueFunction · 0.36