2015-06-17 2 views
0

Go Newb здесь ... Я знаю, что есть проблема с моей структурой, но, похоже, она не работает ... любой совет очень ценится!Trouble create struct for xml

<?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) 
+0

получил его :) '' 'тип OrgResult структура { \t XMLName xml.Name' XML: "результат" ' \t Entities OrgEntities' XML: "субъекты" ' } OrgEntities типа структура { \t Орг [] OrgEntity' XML: "субъект" ' } тип OrgEntity структура { \t ID Int 'XML: "идентификатор, атр"' \t Имя строка 'XML: "имя, атр" \t Тип строки' 'XML: "тип, атр"' } '' ' –

+0

Что не работает ? –

+2

Вы должны поместить свой комментарий в ответ со своего кода, и он решил вашу проблему. –

ответ

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"` 
}