FetchRootElement takes in a decoder and returns the first start element within the xml body. This function is useful in fetching the start element of an XML response and ignore the comments and preamble
(decoder *xml.Decoder)
| 141 | // This function is useful in fetching the start element of an XML response and ignore the |
| 142 | // comments and preamble |
| 143 | func FetchRootElement(decoder *xml.Decoder) (startElement xml.StartElement, err error) { |
| 144 | for { |
| 145 | t, e := decoder.Token() |
| 146 | if e != nil { |
| 147 | return startElement, e |
| 148 | } |
| 149 | |
| 150 | if startElement, ok := t.(xml.StartElement); ok { |
| 151 | return startElement, err |
| 152 | } |
| 153 | } |
| 154 | } |