在嵌套的XML Golang中解组属性

时间:2018-12-15 20:26:19

标签: xml go

我到处搜索,无法找到解决方案。

我正在尝试从Wikipedia获取嵌套xml标记的属性,但是到目前为止,尚无法获取嵌套的属性。我专门尝试从MKMapSnapshotter标记中获取 let polyLine = MKPolyline(coordinates:locations , count: locations.count) var region = MKCoordinateRegionForMapRect(polyLine.boundingMapRect) mapSnapshotOptions.region = region mapSnapshotOptions.scale = UIScreen.main.scale mapSnapshotOptions.size = imageViewRect.size mapSnapshotOptions.showsBuildings = true mapSnapshotOptions.showsPointsOfInterest = true let snapShotter = MKMapSnapshotter(options: mapSnapshotOptions) snapShotter.start { (snapshot, error) in //use snapshot }

这是xml的示例:

pageid

这是我正在使用的结构:

page

,但extract.page.pageid仍然没有返回。我有什么想念/做错了吗?

1 个答案:

答案 0 :(得分:0)

您的结构应更改为此:

type Page struct {
    PageID string `xml:"pageid,attr"`
    Text   string `xml:"extract"`
}

type Extract struct {
    Page Page `xml:"query>pages>page"`
}

fmt.Println(extract.Page.PageID)
fmt.Println(extract.Page.Text)
相关问题