-
-
Save dabio/4239163 to your computer and use it in GitHub Desktop.
Golang Solr result xml parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package solr | |
| import ( | |
| "encoding/xml" | |
| ) | |
| type SolrResponse struct { | |
| Results SolrResults `xml:"result"` | |
| } | |
| type SolrResults struct { | |
| TotalResults int `xml:"numFound,attr"` | |
| Start int `xml:"start,attr"` | |
| Documents []SolrDocument `xml:"doc"` | |
| } | |
| type SolrDocument struct { | |
| Attributes []SolrAttribute `xml:",any"` | |
| } | |
| type SolrAttribute struct { | |
| Name string `xml:"name,attr"` | |
| Value string `xml:",chardata"` | |
| } | |
| func SolrParseXML(data []byte) *SolrResults { | |
| var q SolrResponse | |
| xml.Unmarshal(data, &q) | |
| return &q.Results | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to get any xml-node, not only the str.