• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang xml.Unmarshal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中xml.Unmarshal函数的典型用法代码示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Unmarshal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ListQueues

func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "ListQueues")
	if prefix != "" {
		parms.Set("QueueNamePrefix", prefix)
	}

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	resp, err = self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := listQueuesResponse{}
		if resp.StatusCode == http.StatusOK {
			err = xml.Unmarshal(resp.Body, &xresp)
		} else {
			err = os.NewError("Unexpected response code")
		}
		if err == nil {
			mq = xresp.QueueURL
		}

	}
	return
}
开发者ID:abneptis,项目名称:GoAWS,代码行数:26,代码来源:service.go


示例2: CreateQueue

// Create a queue, returning the Queue object.
func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq *Queue, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "CreateQueue")
	parms.Set("QueueName", name)
	parms.Set("DefaultVisibilityTimeout", strconv.Itoa(dvtimeout))

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
			if resp.StatusCode == http.StatusOK {
				xmlresp := createQueueResponse{}
				err = xml.Unmarshal(resp.Body, &xmlresp)
				if err == nil {
					var qrl *http.URL
					qrl, err = http.ParseURL(xmlresp.QueueURL)
					if err == nil {
						mq = NewQueue(qrl)
					}
				}
			} else {
				err = os.NewError("Unexpected response")
			}
		}
	}

	return
}
开发者ID:abneptis,项目名称:GoAWS,代码行数:32,代码来源:service.go


示例3: showComments

// showComments print comment list.
func showComments(auth string, id string) {
	req, err := http.NewRequest("GET", "https://code.google.com/feeds/issues/p/"+project+"/issues/"+id+"/comments/full", nil)
	if err != nil {
		log.Fatal("failed to get comments:", err)
	}
	req.Header.Set("Authorization", "GoogleLogin "+auth)
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal("failed to get comments:", err)
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		log.Fatal("failed to authenticate:", res.Status)
	}
	var feed Feed
	err = xml.Unmarshal(res.Body, &feed)
	if err != nil {
		log.Fatal("failed to get comments:", err)
	}
	for _, entry := range feed.Entry {
		doc, err := html.Parse(strings.NewReader(entry.Content))
		if err != nil {
			log.Fatal("failed to parse xml:", err)
		}
		text, err := dump(doc)
		if err != nil {
			log.Fatal("failed to parse xml:", err)
		}
		println(entry.Title, "\n", text)
	}
}
开发者ID:andradeandrey,项目名称:goissue,代码行数:32,代码来源:main.go


示例4: CreateLoadBalancer

func (self *ELBHandler) CreateLoadBalancer(zones []string, listeners []ELBListener, name string) (dnsname string, err os.Error) {
	parms := map[string]string{}
	for i := range zones {
		parms["AvailabilityZones.members."+strconv.Itoa(1+i)] = zones[i]
	}
	parms["LoadBalancerName"] = name
	for i := range listeners {
		parms["Listeners.members."+strconv.Itoa(1+i)+".InstancePort"] = strconv.Itoa(listeners[i].InstancePort)
		parms["Listeners.members."+strconv.Itoa(1+i)+".LoadBalancerPort"] = strconv.Itoa(listeners[i].LoadBalancerPort)
		parms["Listeners.members."+strconv.Itoa(1+i)+".Protocol"] = listeners[i].Protocol
	}
	req, err := newQuery(self.signer, self.c.Endpoint(), "CreateLoadBalancer", parms)
	if err == nil {
		var resp *http.Response
		var eresult elbResult
		resp, err = self.c.WriteRequest(req)
		if err == nil {
			err = xml.Unmarshal(resp.Body, &eresult)
			if err == nil {
				if eresult.Error.Code != "" {
					err = eresult.Error
				} else {
					dnsname = eresult.CreateLoadBalancerResult.DNSName
				}
			}
		}
	}
	return
}
开发者ID:tkawachi,项目名称:GoAWS,代码行数:29,代码来源:handler.go


示例5: Peek

// Note: 0 is a valid timeout!!
func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "ReceiveMessage")
	if vt >= 0 {
		parms.Set("VisibilityTimeout", strconv.Itoa(vt))
	}
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
		}
		if err == nil && resp.StatusCode != http.StatusOK {
			err = os.NewError("Unexpected response")
		}
		if err == nil {
			msg := message{}
			err = xml.Unmarshal(resp.Body, &msg)
			if err == nil {
				body, msgid = msg.Body, msg.ReceiptHandle
			}
		}
	}
	return
}
开发者ID:justinbarry,项目名称:GoAWS,代码行数:28,代码来源:queue.go


示例6: getDcbValue

func getDcbValue(period int) (string, os.Error) {
	res, _, err := http.Get(fmt.Sprintf("http://kaijiang.zhcw.com/zhcw/html/ssq/detail_%d.html", period))
	if err != nil {
		return "", err
	}
	defer res.Body.Close()
	js, _ := ioutil.ReadAll(res.Body)
	s := string(js)
	i := strings.Index(s, "中奖号码")
	if i != -1 {
		s := string(s[i:])
		b := strings.Index(s, `<li`)
		e := strings.Index(s, `</ul>`)
		if b > e {
			return "", os.NewError("parse err\n")
		}
		xmlStr := string(s[b : e-1])
		var l Xml
		xmlStr = `<?xml version="1.0" encoding="UTF-8"?><a xmlns="http://domain">` + xmlStr + "</a>"
		fmt.Printf("%s\n", xmlStr)
		if err := xml.Unmarshal(strings.NewReader(xmlStr), &l); err != nil {
			return "", err
		} else {
			var str string
			for _, v := range l.Li {
				str += fmt.Sprintf("%2d|", v)
			}
			return str, nil
		}
	} else {
		return "", os.NewError("404\n")
	}
	return "", nil
}
开发者ID:gaxxx,项目名称:funx,代码行数:34,代码来源:dcb.go


示例7: readSheetsFromZipFile

// readSheetsFromZipFile is an internal helper function that loops
// over the Worksheets defined in the XSLXWorkbook and loads them into
// Sheet objects stored in the Sheets slice of a xlsx.File struct.
func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, os.Error) {
	var workbook *XLSXWorkbook
	var error os.Error
	var rc io.ReadCloser
	workbook = new(XLSXWorkbook)
	rc, error = f.Open()
	if error != nil {
		return nil, error
	}
	error = xml.Unmarshal(rc, workbook)
	if error != nil {
		return nil, error
	}
	sheets := make([]*Sheet, len(workbook.Sheets.Sheet))
	for i, rawsheet := range workbook.Sheets.Sheet {
		worksheet, error := getWorksheetFromSheet(rawsheet, file.worksheets) //
		if error != nil {
			return nil, error
		}
		sheet := new(Sheet)
		sheet.Rows = readRowsFromSheet(worksheet, file.referenceTable)
		sheets[i] = sheet
	}
	return sheets, nil
}
开发者ID:andradeandrey,项目名称:xlsx,代码行数:28,代码来源:lib.go


示例8: GetAttribute

func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList, consist bool) (a []Attribute, err os.Error) {
	var resp *http.Response

	vl := attrs.Values(ATTRIBUTE_LIST)

	vl.Set("Action", "GetAttributes")
	vl.Set("DomainName", self.Name)
	vl.Set("ItemName", item)

	if consist {
		vl.Set("ConsistentRead", "true")
	}

	req := aws.NewRequest(self.URL, "GET", nil, vl)
	err = s.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
	if err == nil {
		resp, err = self.conn.Request(req)
	}
	if err == nil {
		defer resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
	}
	if err == nil {
		var response getattributesresponse
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
		err = xml.Unmarshal(resp.Body, &response)
		if err == nil {
			a = response.Attributes
		}
	}
	return
}
开发者ID:justinbarry,项目名称:GoAWS,代码行数:33,代码来源:domain.go


示例9: DeleteLoadBalancer

// Users note: amazon will only return an error if the request is bad,
// thus an error will not be raised when deleting a non-existent LB.
func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err os.Error) {
	parms := http.Values{}
	parms.Set("Action", "DeleteLoadBalancer")
	parms.Set("LoadBalancerName", name)
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 0)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		err = aws.CodeToError(resp.StatusCode)
	}
	qr := LoadBalancerQueryResult{}
	err = xml.Unmarshal(resp.Body, &qr)
	if err == nil {
		if qr.ErrorCode != "" {
			err = os.NewError(qr.ErrorCode)
		}
	}
	return
}
开发者ID:abneptis,项目名称:GoAWS,代码行数:28,代码来源:service.go


示例10: DescribeInstances

func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic chan Instance) (err os.Error) {
	if filter == nil {
		filter = http.Values{}
	}
	filter.Set("Action", "DescribeInstances")
	req := aws.NewRequest(self.URL, "GET", nil, filter)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := describeInstancesResponse{}
		err := xml.Unmarshal(resp.Body, &xresp)
		if err == nil {
			log.Printf("XRESP == %+v", xresp)
		} else {
			log.Printf("XERR == %+v", err)
		}
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
	}

	return
}
开发者ID:abneptis,项目名称:GoAWS,代码行数:26,代码来源:service.go


示例11: query

func (sns *SNS) query(topic *Topic, message *Message, params map[string]string, resp interface{}) os.Error {
	params["Timestamp"] = time.UTC().Format(time.RFC3339)
	url_, err := url.Parse(sns.Region.SNSEndpoint)
	if err != nil {
		return err
	}

	sign(sns.Auth, "GET", "/", params, url_.Host)
	url_.RawQuery = multimap(params).Encode()
	r, err := http.Get(url_.String())
	if err != nil {
		return err
	}
	defer r.Body.Close()

	//dump, _ := http.DumpResponse(r, true)
	//println("DUMP:\n", string(dump))
	//return nil

	if r.StatusCode != 200 {
		return buildError(r)
	}
	err = xml.Unmarshal(r.Body, resp)
	return err
}
开发者ID:supr,项目名称:sns,代码行数:25,代码来源:sns.go


示例12: query

// Adds common parameters to the "params" map, signs the request,
// adds the signature to the "params" map and sends the request
// to the server.  It then unmarshals the response in to the "resp"
// parameter using xml.Unmarshal()
func (mt *MTurk) query(params map[string]string, operation string, resp interface{}) os.Error {
	service := MTURK_SERVICE
	timestamp := time.UTC().Format(TIMESTAMP_FORMAT)

	params["AWSAccessKeyId"] = mt.Auth.AccessKey
	params["Service"] = service
	params["Timestamp"] = timestamp
	params["Operation"] = operation

	// make a copy
	url := *mt.URL

	sign(mt.Auth, service, operation, timestamp, params)
	url.RawQuery = multimap(params).Encode()
	r, err := http.Get(url.String())
	if err != nil {
		return err
	}
	dump, _ := http.DumpResponse(r, true)
	println("DUMP:\n", string(dump))
	if r.StatusCode != 200 {
		return os.NewError(fmt.Sprintf("%d: unexpected status code", r.StatusCode))
	}
	err = xml.Unmarshal(r.Body, resp)
	r.Body.Close()
	return err
}
开发者ID:laslowh,项目名称:mturk,代码行数:31,代码来源:mturk.go


示例13: fetchPhotosInGallery

func fetchPhotosInGallery(filename string, op Operation) {
	defer op.Done()

	f, err := os.Open(filename, os.O_RDONLY, 0)
	if err != nil {
		addError(fmt.Sprintf("Failed to open %s: %v", filename, err))
		return
	}
	defer f.Close()
	mediaSet := new(MediaSet)
	err = xml.Unmarshal(f, mediaSet)
	if err != nil {
		addError(fmt.Sprintf("Failed to unmarshal %s: %v", filename, err))
		return
	}

	// Learn about new galleries, potentially?
	for _, url := range mediaSet.LinkedFrom.InfoURL {
		noteGallery(url)
	}
	for _, url := range mediaSet.LinkedTo.InfoURL {
		noteGallery(url)
	}

	//log.Printf("Parse of %s is: %q", filename, mediaSet)
	for _, item := range mediaSet.MediaSetItems.MediaSetItem {
		item.key = findKey(item.InfoURL, picPattern)
		//log.Printf("   pic: %s", item.InfoURL)
		notePhoto(&item)
	}
}
开发者ID:nagyistge,项目名称:fotobilder-spiegel,代码行数:31,代码来源:spiegel.go


示例14: TestUnmarshallWorksheet

// Test we can succesfully unmarshal the sheetN.xml files within and
// XLSX file into an XLSXWorksheet struct (and it's related children).
func TestUnmarshallWorksheet(t *testing.T) {
	var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:B2"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="C2" sqref="C2"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:2"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c></row><row r="2" spans="1:2"><c r="A2" t="s"><v>2</v></c><c r="B2" t="s"><v>3</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>`)
	worksheet := new(XLSXWorksheet)
	error := xml.Unmarshal(sheetxml, worksheet)
	if error != nil {
		t.Error(error.String())
		return
	}
	if worksheet.Dimension.Ref != "A1:B2" {
		t.Error(fmt.Sprintf("Expected worksheet.Dimension.Ref == 'A1:B2', got %s", worksheet.Dimension.Ref))
	}
	if len(worksheet.SheetViews.SheetView) == 0 {
		t.Error(fmt.Sprintf("Expected len(worksheet.SheetViews.SheetView) == 1, got %d", len(worksheet.SheetViews.SheetView)))
	}
	sheetview := worksheet.SheetViews.SheetView[0]
	if sheetview.TabSelected != "1" {
		t.Error(fmt.Sprintf("Expected sheetview.TabSelected == '1', got %s", sheetview.TabSelected))
	}
	if sheetview.WorkbookViewID != "0" {
		t.Error(fmt.Sprintf("Expected sheetview.WorkbookViewID == '0', got %s", sheetview.WorkbookViewID))
	}
	if sheetview.Selection.ActiveCell != "C2" {
		t.Error(fmt.Sprintf("Expeceted sheetview.Selection.ActiveCell == 'C2', got %s", sheetview.Selection.ActiveCell))
	}
	if sheetview.Selection.SQRef != "C2" {
		t.Error(fmt.Sprintf("Expected sheetview.Selection.SQRef == 'C2', got %s", sheetview.Selection.SQRef))
	}
	if worksheet.SheetFormatPr.BaseColWidth != "10" {
		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.BaseColWidth == '10', got %s", worksheet.SheetFormatPr.BaseColWidth))
	}
	if worksheet.SheetFormatPr.DefaultRowHeight != "15" {
		t.Error(fmt.Sprintf("Expected worksheet.SheetFormatPr.DefaultRowHeight == '15', got %s", worksheet.SheetFormatPr.DefaultRowHeight))
	}
	if len(worksheet.SheetData.Row) == 0 {
		t.Error(fmt.Sprintf("Expected len(worksheet.SheetData.Row) == '2', got %d", worksheet.SheetData.Row))
	}
	row := worksheet.SheetData.Row[0]
	if row.R != "1" {
		t.Error(fmt.Sprintf("Expected row.r == '1', got %s", row.R))
	}
	if row.Spans != "1:2" {
		t.Error(fmt.Sprintf("Expected row.Spans == '1:2', got %s", row.Spans))
	}
	if len(row.C) != 2 {
		t.Error(fmt.Sprintf("Expected len(row.C) == 2, got %s", row.C))
	}
	c := row.C[0]
	if c.R != "A1" {
		t.Error(fmt.Sprintf("Expected c.R == 'A1' got %s", c.R))
	}
	if c.T != "s" {
		t.Error(fmt.Sprintf("Expected c.T == 's' got %s", c.T))
	}
	if c.V.Data != "0" {
		t.Error(fmt.Sprintf("Expected c.V.Data == '0', got %s", c.V.Data))
	}

}
开发者ID:remigijusj,项目名称:xlsx,代码行数:61,代码来源:worksheet_test.go


示例15: Unmarshal

func Unmarshal(xmlStr string) XMLdata {
	var buf = bytes.NewBuffer([]byte(xmlStr))
	r := XMLdata{}
	if err := xml.Unmarshal(buf, &r); err != nil {
		fmt.Println(err)
	}
	return r
}
开发者ID:peera,项目名称:go-websocket,代码行数:8,代码来源:echo.go


示例16: readpmap

func readpmap(r io.Reader, canvas *svg.SVG) {
	var pm Pmap
	if err := xml.Unmarshal(r, &pm); err == nil {
		drawpmap(pm, canvas)
	} else {
		fmt.Fprintf(os.Stderr, "Unable to parse pmap (%v)\n", err)
	}
}
开发者ID:johan,项目名称:svgo,代码行数:8,代码来源:pmap.go


示例17: readbg

// readbg reads and parses the XML specification
func readbg(r io.Reader, s *svg.SVG) {
	var bg Bulletgraph
	if err := xml.Unmarshal(r, &bg); err == nil {
		drawbg(bg, s)
	} else {
		fmt.Fprintf(os.Stderr, "%v\n", err)
	}
}
开发者ID:krasin,项目名称:svgo,代码行数:9,代码来源:bulletgraph.go


示例18: printMetadataForKey

func printMetadataForKey(c *irc.Conn, channel string, key string) {
	r, _, _ := http.Get("http://gdata.youtube.com/feeds/api/videos/" + key)
	if r.StatusCode != http.StatusOK {
		return
	}
	var m Video = Video{xml.Name{}, ""}
	xml.Unmarshal(r.Body, &m)
	c.Privmsg(channel, "  -> "+m.Title)
}
开发者ID:broady,项目名称:gobby,代码行数:9,代码来源:youtuber.go


示例19: parseUI

func parseUI(reader io.Reader) (*UI, os.Error) {
	ui := &UI{}

	if err := xml.Unmarshal(reader, ui); err != nil {
		return nil, err
	}

	return ui, nil
}
开发者ID:wiloe,项目名称:walk,代码行数:9,代码来源:ui2walk.go


示例20: ParseResponse

func (self Response) ParseResponse() (resp SimpledbResponse, err os.Error) {
	err = xml.Unmarshal(self.Body, &resp)
	if err != nil {
		return
	}
	if resp.Errors.Error.Code != "" {
		err = os.NewError(resp.Errors.Error.Code)
	}
	return
}
开发者ID:tkawachi,项目名称:GoAWS,代码行数:10,代码来源:response.go



注:本文中的xml.Unmarshal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dom.ParseString函数代码示例发布时间:2022-05-28
下一篇:
Golang operation.Operation类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap