dongrongdao8902 2016-10-01 23:09
浏览 66
已采纳

Golang XML解析问题

I have just started experimenting with Google's GO (Golang) language, and have run into a problem that I would like to solve efficiently. So I would like to extract some data from an XML file, that is available online (I get it as the response of a polling session), but I don't know how to get started. Should I download the source code of the page, store it locally and extract the data that way or is there a possibility to extract the data without downloading the whole thing? Thank you!

<?xml version="1.0" encoding="utf-8"?>
  • 写回答

1条回答 默认 最新

  • doulan9287 2016-10-02 00:16
    关注

    Since its available online you can use net/http client to retrieve the xml. Then you can use encoding/xml package and convert the response body to struct object, it has xml.Unmarshal method to convert xml string to struct - hence you should write the struct first.

    net/http example available

    encoding/xml example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?