Skip to content

Instantly share code, notes, and snippets.

@nickjenkin
Created July 25, 2012 10:06
Show Gist options
  • Save nickjenkin/3175420 to your computer and use it in GitHub Desktop.
Save nickjenkin/3175420 to your computer and use it in GitHub Desktop.
Golang Solr result xml parser
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