LoadURL loads the XML document from the specified URL.
(url string)
| 19 | |
| 20 | // LoadURL loads the XML document from the specified URL. |
| 21 | func LoadURL(url string) (*Node, error) { |
| 22 | resp, err := http.Get(url) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | defer resp.Body.Close() |
| 27 | // Make sure the Content-Type has a valid XML MIME type |
| 28 | if xmlMIMERegex.MatchString(resp.Header.Get("Content-Type")) { |
| 29 | return Parse(resp.Body) |
| 30 | } |
| 31 | return nil, fmt.Errorf("invalid XML document(%s)", resp.Header.Get("Content-Type")) |
| 32 | } |
| 33 | |
| 34 | // Parse returns the parse tree for the XML from the given Reader. |
| 35 | func Parse(r io.Reader) (*Node, error) { |
searching dependent graphs…