Golang 解析带命名空间的 XML
遇到的问题 在写业余项目时遇到一个xml无法解析的问题,情景如下。使用以下 Golang 解析 YouTube 的 RSS 返回的 XML ,无法获得 XML 内<media:thumbnail> 内的数据。 type YoutubeRSS struct { XMLName xml.Name `xml:"feed"` Entry []struct { Title string `xml:"title"` Link struct { Href string `xml:"href,attr"` } `xml:"link"` Updated time.Time `xml:"updated"` MediaGrop struct { MediaThumbnail struct { Url string `xml:"url,attr"` } `xml:"media:thumbnail"` } `xml:"media:group"` } `xml:"entry"` } <?xml version="1.0" encoding="UTF-8"?> <feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns:media="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom"> <link rel="self" href="http://www.youtube.com/feeds/videos.xml?channel_id=UCSI11yVCM5x45_iiL5YcQZw"/> <id>yt:channel:UCSI11yVCM5x45_iiL5YcQZw</id> <yt:channelId>UCSI11yVCM5x45_iiL5YcQZw</yt:channelId> <title>Priscilla Abby 蔡恩雨</title> <link rel="alternate" href="https://www....