這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。xml是一個遠程地址
<returnsms><returnstatus>Success</returnstatus><message>ok</message><remainpoint>150528</remainpoint><taskID>518334</taskID><successCounts>1</successCounts></returnsms>
解析
//xml的struct結構type Duanxin struct {Returnstatus string `xml:"returnstatus"`Message string `xml:"message"`Remainpoint string `xml:"remainpoint"`TaskID string `xml:"taskID"`SuccessCounts string `xml:"successCounts"`}//發手機簡訊func Send_duanxin(mobile int64, content string) (dx Duanxin, err error) {m := strconv.FormatInt(mobile, 10)if len(content) < 30 {return dx, errors.New("內容少於30個字元")}content = content + "【XX公司發送】"SendUrl := beego.AppConfig.String("sendurl")url := SendUrl + "&mobile=" + m + "&content=" + contentresp, err := http.Get(url)if err != nil {return dx, err}defer resp.Body.Close()body, err := ioutil.ReadAll(resp.Body)if err != nil {return dx, err}err = xml.Unmarshal(body, &dx)//好方便,就這樣就解析了xml,so關鍵是xml的結構return dx, err}