извлекать несколько детей в go xml unmarshalling не работает правильно - PullRequest
0 голосов
/ 04 ноября 2019

У меня есть следующее structs:

type Listing struct {
            DetailedCharacteristics struct {
                ExteriorTypes struct {
                        Text         string `xml:",chardata"`
                        ExteriorType string `xml:"ExteriorType"`
                } `xml:"ExteriorTypes"`
            }
}

type Listings struct {
    XMLName xml.Name `xml:"Listings"`
    Listings []Listing `xml:"Listing"`
}

оно получает unmarshalled by:

xmlFile,err:=os.Open(spotXmlFile)
defer xmlFile.Close()
var listings Listings
xml.NewDecoder(xmlFile).Decode(&listings)

Вот мой xml:

<Listings>
    <Listing>
        <DetailedCharacteristics>
            <ExteriorTypes>
                <ExteriorType>Brick</ExteriorType>
                <ExteriorType>Vinyl Siding</ExteriorType>
                </ExteriorTypes>
        </DetailedCharacteristics>
    </Listing>
</Listings>

Я пытаюсь извлечь данные, которые приводят к строковому кирпичу

listings.Listings[i].DetailedCharacteristics.ExteriorTypes.ExteriorType

Я также пытаюсь:

 var finishes []string
 for i,v:=range listings.Listings[i].DetailedCharacteristics.ExteriorTypes.ExteriorType {
     finishes=append(finishes,v)
 }
 finishStr:=strings.Join(finishes[:],",")

Я пытаюсь выяснить, как извлечь все строки данных XML. Я посмотрел здесь:

сообщение в стеке на xml отменяет вызов нескольких детей

, но не удалось.

он возвращает одно значение, когда есть несколько дочерних элементов

...