无法为xml创建结构

时间:2015-06-17 13:55:38

标签: xml go

Go Newb here ...我知道我的结构存在问题,但似乎无法使其工作......任何建议都非常感谢!

<?xml version='1.0' ?>
<result called_on="2015-06-17 12:49:41.014435+00">
  <entities count="0" start="0">
    <entity name="Aaron Test" id="12345" type="organization" />
    <entity name="MagicOne" id="102301" type="organization" />
  </entities>
  <status code="ok" />
</result>


type OrgResult struct {
    XMLName  xml.Name    `xml:"result"`
    Entities OrgEntities `xml:"entity"`
}
type OrgEntities struct {
    Org OrgEntity `xml:"entity"`
}
type OrgEntity struct {
    ID   int    `xml:"id,attr"`
    Name string `xml:"name,attr"`
    Type string `xml:"type,attr"`
}

OrgResult := OrgResult{}
xml.Unmarshal(body, &OrgResult)
fmt.Println(body)
fmt.Println(OrgResult)

1 个答案:

答案 0 :(得分:0)

得到了它:)

type OrgResult struct { 
    XMLName xml.Name `xml:"result"` 
    Entities OrgEntities `xml:"entities"` 
} 
type OrgEntities struct { 
    Org []OrgEntity `xml:"entity"` 
} 
type OrgEntity struct { 
    ID int `xml:"id,attr"` 
    Name string `xml:"name,attr"` 
    Type string `xml:"type,attr"` 
}