Hello,
So I'm trying to unmarshal an XML with namespaces in go but i just can't
find the right parser to do so.
My code:
package main
import "fmt"
import "encoding/xml"
type Root struct {
MNResultsResults []ls `xml:"xmlns ls,
MNResultsResults>ssResultSet>ssResult"`
}
type ls struct {
Data float64 `xml:"xmlns ls, cpc"`
}
func main() {
x := `<?xml version="1.0" encoding="utf-8"?>
<ls:MNResultsResults xmlns:ls="urn:MNResultsResults">
<ls:ssResultSet ls:firstResult="1" ls:numResults="2" ls:totalHits="2">
<ls:ssResult ls:id="1">
<ls:abstract><![CDATA[some data.]]></ls:abstract>
<ls:title><![CDATA[some data]]></ls:title>
<ls:url><![CDATA[data]]></ls:url>
<ls:displayUrl><![CDATA[some data]]></ls:displayUrl>
<ls:cpc>float value</ls:cpc>
</ls:ssResult>
<ls:ssResult ls:id="2">
<ls:abstract><![CDATA[some data.]]></ls:abstract>
<ls:title><![CDATA[some data.]]></ls:title>
<ls:url><![CDATA[some data]]></ls:url>
<ls:displayUrl><![CDATA[some data]]></ls:displayUrl>
<ls:cpc>float value</ls:cpc>
</ls:ssResult>
</ls:ssResultSet>
</ls:MNResultsResults>`
r := Root{}
xml.Unmarshal([]byte(x), &r)
fmt.Printf("%+v", r)
}
I've tried several combinations, but i always get a nil result.
Any ideas how to parse this?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.