Created
July 25, 2012 10:06
-
-
Save nickjenkin/3175420 to your computer and use it in GitHub Desktop.
Golang Solr result xml parser
This file contains 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:"str"` | |
} | |
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment