Skip to content

Instantly share code, notes, and snippets.

@dabio
Forked from nickjenkin/gist:3175420
Created December 8, 2012 07:50
Show Gist options
  • Save dabio/4239163 to your computer and use it in GitHub Desktop.
Save dabio/4239163 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:",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
}
@dabio
Copy link
Author

dabio commented Dec 8, 2012

Updated to get any xml-node, not only the str.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment