当前位置: 首页>>代码示例>>Golang>>正文


Golang xmlpath.Parse函数代码示例

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


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

示例1: Paser

func (hfy *httphfy) Paser(reader io.Reader) *Response {
	rsp := new(Response)
	root, err := xmlpath.Parse(reader)
	if err != nil {
		rsp.Status = FAILED
		rsp.Msg = "短信平台服务错误"
		return rsp
	}

	pathstatus := xmlpath.MustCompile("//returnsms/returnstatus")
	pathmessage := xmlpath.MustCompile("//returnsms/message")

	if status, ok := pathstatus.String(root); ok {
		if status == "Success" {
			rsp.Status = SUCCESS
		} else {
			rsp.Status = FAILED
		}
	} else {
		rsp.Status = FAILED
		rsp.Msg = "短信平台服务错误"
		return rsp
	}

	if message, ok := pathmessage.String(root); ok {
		rsp.Msg = "短信平台:" + message
	}
	return rsp
}
开发者ID:xjplke,项目名称:smsadapter,代码行数:29,代码来源:http_hfy.go

示例2: lookupItem

// lookupItem from Amazon store using itemId. Uses ItemLookup method from Product Advertising API.
func lookupItem(cred AWSCredentials, itemId string) *xmlpath.Node {

	// create request
	q := newAWSQuery(cred.host, cred.accessKey)
	q.params["Operation"] = "ItemLookup"
	q.params["ItemId"] = itemId
	q.params["ResponseGroup"] = "ItemAttributes"

	// create signature
	query, signature := signRequest(q, cred)

	// make request url
	request := "http://" + cred.host + "/onca/xml" + "?" + query + "&Signature=" + signature

	// HTTP GET
	resp, _ := http.Get(request)

	// parse response xml
	root, err := xmlpath.Parse(resp.Body)
	if err != nil {
		panic(err)
	}

	return root
}
开发者ID:rlaakso,项目名称:amzn,代码行数:26,代码来源:item-lookup.go

示例3: main

func main() {
	f, err := os.Open("test3.xml")
	if err != nil {
		fmt.Println(err)
		return
	}
	n, err := xmlpath.Parse(f)
	f.Close()
	if err != nil {
		fmt.Println(err)
		return
	}
	q1 := xmlpath.MustCompile("//item")
	if _, ok := q1.String(n); !ok {
		fmt.Println("no item")
	}
	q2 := xmlpath.MustCompile("//price")
	for it := q2.Iter(n); it.Next(); {
		fmt.Println(it.Node())
	}
	q3 := xmlpath.MustCompile("//name")
	names := []*xmlpath.Node{}
	for it := q3.Iter(n); it.Next(); {
		names = append(names, it.Node())
	}
	if len(names) == 0 {
		fmt.Println("no names")
	}
}
开发者ID:travis1230,项目名称:RosettaCodeData,代码行数:29,代码来源:xml-xpath-2.go

示例4: FindByInventoryPath

func (vim *VimClient) FindByInventoryPath(inventoryPath string) (vmId string, err error) {
	data := struct {
		InventoryPath string
	}{
		inventoryPath,
	}
	t := template.Must(template.New("FindByInventoryPath").Parse(FindByInventoryPathRequestTemplate))

	log.Printf("Looking for '%s'", inventoryPath)

	request, _ := vim.prepareRequest(t, data)
	response, err := vim.Do(request)
	// defer response.Body.Close()
	if err != nil {
		err = fmt.Errorf("Error calling FindByInventoryPath: '%s'", err.Error())
		return
	}
	body, _ := ioutil.ReadAll(response.Body)
	// log.Printf("RESPONSE BODY BELOW:\n============\n%s\n===========\nEND RESPONSE BODY\n", string(body))
	root, _ := xmlpath.Parse(bytes.NewBuffer(body))
	path := xmlpath.MustCompile("//*/FindByInventoryPathResponse/returnval")
	if vmId, ok := path.String(root); ok {
		return vmId, err
	} else {
		err := fmt.Errorf("Found nothing.")
		return vmId, err
	}
}
开发者ID:justinclayton,项目名称:packer-builder-vsphere,代码行数:28,代码来源:vim.go

示例5: XPath

func (r *XMLResource) XPath(xpath string) (string, bool) {
	path := xmlpath.MustCompile(xpath)
	b := bytes.NewBufferString(r.Body())

	root, _ := xmlpath.Parse(b)

	return path.String(root)
}
开发者ID:OpenNebula,项目名称:goca,代码行数:8,代码来源:goca.go

示例6: XPathIter

func (r *XMLResource) XPathIter(xpath string) *XMLIter {
	path := xmlpath.MustCompile(xpath)
	b := bytes.NewBufferString(string(r.Body()))

	root, _ := xmlpath.Parse(b)

	return &XMLIter{iter: path.Iter(root)}
}
开发者ID:OpenNebula,项目名称:goca,代码行数:8,代码来源:goca.go

示例7: TestRootText

func (s *BasicSuite) TestRootText(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(trivialXml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/")
	result, ok := path.String(node)
	c.Assert(ok, Equals, true)
	c.Assert(result, Equals, "abcdefg")
}
开发者ID:containerx,项目名称:machine,代码行数:8,代码来源:all_test.go

示例8: parseVmPowerStateProperty

func parseVmPowerStateProperty(body *bytes.Buffer) (value string) {
	root, _ := xmlpath.Parse(bytes.NewBuffer(body.Bytes()))
	path := xmlpath.MustCompile("//*/RetrievePropertiesResponse/returnval/propSet[name='runtime']/val/powerState")
	if value, ok := path.String(root); ok {
		return value
	} else {
		return ""
	}
}
开发者ID:justinclayton,项目名称:packer-builder-vsphere,代码行数:9,代码来源:vm.go

示例9: TestLibraryTable

func (s *BasicSuite) TestLibraryTable(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(libraryXml))
	c.Assert(err, IsNil)
	for _, test := range libraryTable {
		cmt := Commentf("xml path: %s", test.path)
		path, err := xmlpath.Compile(test.path)
		if want, ok := test.result.(cerror); ok {
			c.Assert(err, ErrorMatches, string(want), cmt)
			c.Assert(path, IsNil, cmt)
			continue
		}
		c.Assert(err, IsNil)
		switch want := test.result.(type) {
		case string:
			got, ok := path.String(node)
			c.Assert(ok, Equals, true, cmt)
			c.Assert(got, Equals, want, cmt)
			c.Assert(path.Exists(node), Equals, true, cmt)
			iter := path.Iter(node)
			iter.Next()
			node := iter.Node()
			c.Assert(node.String(), Equals, want, cmt)
			c.Assert(string(node.Bytes()), Equals, want, cmt)
		case []string:
			var alls []string
			var allb []string
			iter := path.Iter(node)
			for iter.Next() {
				alls = append(alls, iter.Node().String())
				allb = append(allb, string(iter.Node().Bytes()))
			}
			c.Assert(alls, DeepEquals, want, cmt)
			c.Assert(allb, DeepEquals, want, cmt)
			s, sok := path.String(node)
			b, bok := path.Bytes(node)
			if len(want) == 0 {
				c.Assert(sok, Equals, false, cmt)
				c.Assert(bok, Equals, false, cmt)
				c.Assert(s, Equals, "")
				c.Assert(b, IsNil)
			} else {
				c.Assert(sok, Equals, true, cmt)
				c.Assert(bok, Equals, true, cmt)
				c.Assert(s, Equals, alls[0], cmt)
				c.Assert(string(b), Equals, alls[0], cmt)
				c.Assert(path.Exists(node), Equals, true, cmt)
			}
		case exists:
			wantb := bool(want)
			ok := path.Exists(node)
			c.Assert(ok, Equals, wantb, cmt)
			_, ok = path.String(node)
			c.Assert(ok, Equals, wantb, cmt)
		}
	}
}
开发者ID:containerx,项目名称:machine,代码行数:56,代码来源:all_test.go

示例10: ExtractToken

func ExtractToken(s string) string {
	root, err := xmlpath.Parse(strings.NewReader(s))
	if err != nil {
		log.Fatal(err)
	}
	if value, ok := path.String(root); ok {
		return value
	}
	return ""
}
开发者ID:miku,项目名称:pmharvest,代码行数:10,代码来源:main.go

示例11: parseVmPropertyValue

func parseVmPropertyValue(prop string, body *bytes.Buffer) (value string) {
	root, _ := xmlpath.Parse(body)
	pathString := strings.Join([]string{"//*/RetrievePropertiesResponse/returnval/propSet[name='", prop, "']/val"}, "")
	path := xmlpath.MustCompile(pathString)
	if value, ok := path.String(root); ok {
		return value
	} else {
		return ""
	}
}
开发者ID:justinclayton,项目名称:packer-builder-vsphere,代码行数:10,代码来源:vm.go

示例12: getXPathValue

func getXPathValue(xml string, eomfile EomFile, lookupPath string) (string, bool) {
	path := xmlpath.MustCompile(lookupPath)
	root, err := xmlpath.Parse(strings.NewReader(xml))
	if err != nil {
		warnLogger.Printf("Cannot parse XML of eomfile using xpath [%v], error: [%v]", err.Error(), lookupPath)
		return "", false
	}
	xpathValue, ok := path.String(root)
	return xpathValue, ok

}
开发者ID:Financial-Times,项目名称:publish-availability-monitor,代码行数:11,代码来源:methodeContent.go

示例13: parseTaskIdFromResponse

func parseTaskIdFromResponse(response *http.Response) (value string) {
	body, _ := ioutil.ReadAll(response.Body)
	root, _ := xmlpath.Parse(bytes.NewBuffer(body))

	path := xmlpath.MustCompile("//*/CloneVM_TaskResponse/returnval")
	if value, ok := path.String(root); ok {
		return value
	} else {
		return ""
	}
}
开发者ID:justinclayton,项目名称:packer-builder-vsphere,代码行数:11,代码来源:vm.go

示例14: BenchmarkSimplePathString

func (s *BasicSuite) BenchmarkSimplePathString(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(instancesXml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/DescribeInstancesResponse/reservationSet/item/instancesSet/item/instanceType")
	var str string
	c.ResetTimer()
	for i := 0; i < c.N; i++ {
		str, _ = path.String(node)
	}
	c.StopTimer()
	c.Assert(str, Equals, "m1.small")
}
开发者ID:containerx,项目名称:machine,代码行数:12,代码来源:all_test.go

示例15: BenchmarkSimplePathExists

func (s *BasicSuite) BenchmarkSimplePathExists(c *C) {
	node, err := xmlpath.Parse(bytes.NewBuffer(instancesXml))
	c.Assert(err, IsNil)
	path := xmlpath.MustCompile("/DescribeInstancesResponse/reservationSet/item/instancesSet/item/instanceType")
	var exists bool
	c.ResetTimer()
	for i := 0; i < c.N; i++ {
		exists = path.Exists(node)
	}
	c.StopTimer()
	c.Assert(exists, Equals, true)
}
开发者ID:containerx,项目名称:machine,代码行数:12,代码来源:all_test.go


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