go - Golang Xml Unmarshal, No value -
type vasthtml struct { vast struct { version string `xml:"version,attr"` ad struct { id string `xml:"id,attr"` inline struct { adsystem string `xml:"adsystem"` adtitle string `xml:"adtitle"` description string `xml:"description"` error string `xml:"error"` impression []string `xml:"impression"` creatives struct { creative []struct { sequence string `xml:"sequence,attr"` id string `xml:"id,attr"` linear struct { duration string `xml:"duration"` trackingevents struct { tracking []string `xml:"tracking"` } `xml:"trackingevents"` videoclicks struct { clickthrough string `xml:"clickthrough"` customclick []string `xml:"customclick"` } `xml:"videoclicks"` mediafiles struct { mediafile []struct { delivery string `xml:"delivery,attr"` bitrate string `xml:"bitrate,attr"` width string `xml:"width,attr"` height string `xml:"height,attr"` type string `xml:"type,attr"` } `xml:"mediafile"` } `xml:"mediafiles"` } `xml:"linear"` companionads struct { companion []struct { width string `xml:"width,attr"` height string `xml:"height,attr"` staticresource string `xml:"staticresource"` trackingevents string `xml:"trackingevents"` companionclickthrough string `xml:"companionclickthrough"` } `xml:"companion"` } `xml:"companionads"` } `xml:"creative"` } `xml:"creatives"` extensions string `xml:"extensions"` } `xml:"inline"` } `xml:"ad"` } `xml:"vast"`
}
func main() { resp, err := http.get("http://ad3.liverail.com/?lr_publisher_id=1331&lr_campaign_id=229&lr_schema=vast2") if err != nil { fmt.println(err) os.exit(1) } defer resp.body.close() xmldatafromhttp, err := ioutil.readall(resp.body) if err != nil { fmt.println(err) os.exit(1) } fmt.println(os.stdout, string(xmldatafromhttp)) // read xml http response var xmldata vasthtml err = xml.unmarshal(xmldatafromhttp, &xmldata) if err != nil { panic(err) } fmt.printf("xml===>: ", xmldata.vast) }
hello everone, after unmarshaling xmlvast url that's give struct without value. when copy content of xmlvast in file , try unmarshal it give me same responce struct without value.
thank in advance.
you trying unmarshal xml document root of <vast>
struct of type vasthtml
, contains vast
first field.
pass vast
element directly unmarshal
function if want decode into.
err = xml.unmarshal(xmldatafromhttp, &xmldata.vast)
Comments
Post a Comment