Golang XML parsing

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. XML is a remote address
<returnsms><returnstatus>Success</returnstatus><message>ok</message>< remainpoint>150528</remainpoint><taskid>518334</taskid><successcounts>1</ Successcounts></returnsms>

Analytical

struct struct of XML type duanxin struct {returnstatus  string ' xml: ' returnstatus ' ' Message       string ' xml: ' message ' Remainpoint   string ' xml: ' Remainpoint ' ' TaskID        string ' xml: ' TaskID ' ' successcounts string ' xml: ' successcounts "'}//texting func send_duanxin (mobile Int64, content String) (dx duanxin, err Error) {m: = StrConv. Formatint (MOBILE) If Len (content) < {return DX, errors. New ("content less than 30 characters")}content = content + "xx company sent" "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)//good convenience, so that the resolution of the XML,SO key is the structure of XML return DX, err}





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.