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


Golang xmlpath.MustCompile函数代码示例

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


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

示例1: 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

示例2: 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

示例3: front_parse

func front_parse(c_front_urls chan string, c_front_page chan []byte, c_doc_urls chan string, wg *sync.WaitGroup) {
	front_page := <-c_front_page
	//fmt.Printf("%s\n", string(front_page))
	//path := xmlpath.MustCompile("/html/body/div/div[2]/div/div[3]/div/div[1]/div[1]/h1/text()") //title
	doc_urls_xpath := xmlpath.MustCompile("/html/body/div[@id=\"page_align\"]/div[@id=\"page_width\"]/div[@id=\"ContainerMain\"]/div[@class=\"content-border list\"]/div[@class=\"content-color\"]/div[@class=\"list-lbc\"]//a/@href") //doc urls
	next_front_urls_xpath := xmlpath.MustCompile("/html/body/div[@id=\"page_align\"]/div[@id=\"page_width\"]/div[@id=\"ContainerMain\"]/nav/ul[@id=\"paging\"]/li[@class=\"page\"]")                                                   //next url
	/*
		front_page_noscript := remove_noscript(front_page)
		fix_html := fix_broken_html(front_page_noscript)
		utf8_reader := decode_utf8(fix_html)
		root, err := xmlpath.ParseHTML(utf8_reader)*/

	utf8_reader := decode_utf8(string(front_page))
	doc_page_noscript := remove_noscript(utf8_reader)

	fix_html := fix_broken_html(doc_page_noscript)

	//fmt.Println(string(fix_html))

	root, err := xmlpath.ParseHTML(strings.NewReader(fix_html))

	if err != nil {
		//log.Println("ca rentre")
		log.Fatal("FRONT PAGE", err)
	}

	doc_urls := doc_urls_xpath.Iter(root)
	for doc_urls.Next() {
		doc_url := doc_urls.Node().String()
		c_doc_urls <- doc_url
		//log.Println( "Doc URL:", doc_url)  //<-- DOC URL
	}

	prev_next_front_urls := next_front_urls_xpath.Iter(root)
	var node *xmlpath.Node

	for prev_next_front_urls.Next() {
		node = prev_next_front_urls.Node()
	}

	href_xpath := xmlpath.MustCompile("a/@href")
	if next_front_url, ok := href_xpath.String(node); ok {
		c_front_urls <- next_front_url
		log.Println("Next Front URL:", next_front_url)
		wg.Add(1)
		go front_worker(c_front_urls, c_front_page, c_doc_urls, wg)
	} else {
		log.Println("No Next Front URL")
		log.Println("Front DONE")
		return
	}
}
开发者ID:peondusud,项目名称:go.scrap.lbc,代码行数:52,代码来源:lbc_front_page.go

示例4: tarballsFrom

func tarballsFrom(source tarballSource) ([]*Tarball, error) {
	resp, err := http.Get(source.url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("cannot read http response: %v", err)
	}
	clearScripts(data)
	root, err := xmlpath.ParseHTML(bytes.NewBuffer(data))
	if err != nil {
		return nil, err
	}
	var tbs []*Tarball
	iter := xmlpath.MustCompile(source.xpath).Iter(root)
	for iter.Next() {
		s := iter.Node().String()
		if strings.HasPrefix(s, "//") {
			s = "https:" + s
		}
		if tb, ok := parseURL(s); ok {
			tbs = append(tbs, tb)
		}
	}
	if len(tbs) == 0 {
		return nil, fmt.Errorf("no downloads available at " + source.url)
	}
	return tbs, nil
}
开发者ID:uin57,项目名称:godeb,代码行数:31,代码来源:main.go

示例5: loadXpath

func loadXpath(response *http.Response, xpath string) ([]byte, error) {
	body, err := ioutil.ReadAll(response.Body)
	panicError(err)

	// Parse body to see if login worked
	//	reader := strings.NewReader(body)
	root, err := html.Parse(bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}

	var b bytes.Buffer
	html.Render(&b, root)
	fixedHtml := b

	//	body = bytes.NewReader(fixedHtml)
	xmlroot, xmlerr := xmlpath.ParseHTML(bytes.NewReader(fixedHtml.Bytes()))

	if xmlerr != nil {
		return nil, xmlerr
	}

	path := xmlpath.MustCompile(xpath)
	if value, ok := path.Bytes(xmlroot); ok {
		return value, nil
	}

	return nil, errors.New("Could not find xpath")
}
开发者ID:Fapiko,项目名称:simunomics-frontend,代码行数:29,代码来源:service.go

示例6: print_simple_selector

func print_simple_selector(pathString string) {
	path := xmlpath.MustCompile(pathString)

	if value, ok := path.String(read_xml()); ok {
		fmt.Println(value)
	}
}
开发者ID:bluerail,项目名称:zabbix-passenger,代码行数:7,代码来源:zabbix-passenger.go

示例7: main

func main() {

	if os.Getenv("AWS_KEY") == "" || len(os.Args) != 2 {
		fmt.Fprint(os.Stderr, "Usage: amzn-item-lookup <itemId>.\nAWS credentials are read from the environment variables AWS_KEY and AWS_SECRET.\n")
		os.Exit(-1)
	}

	// Construct AWS credentials
	var cred AWSCredentials
	cred.host = "ecs.amazonaws.co.uk"
	cred.accessKey = os.Getenv("AWS_KEY")
	cred.secret = os.Getenv("AWS_SECRET")

	// lookup item by id
	itemId := os.Args[1]
	itemXml := lookupItem(cred, itemId)

	// find ItemAttributes block
	xml := xmlpath.MustCompile("//ItemAttributes")
	iter := xml.Iter(itemXml)
	if !iter.Next() {
		panic("Cannot parse response! [Wrong credentials?]")
	}
	item := parseItemAttributes(iter.Node())
	//	fmt.Println(item)

	// print output
	fmt.Print(strings.Join(item.author, ", "), DELIM)
	fmt.Print(item.title, DELIM, item.publisher, DELIM, item.edition, " ed", DELIM, item.publicationDate, DELIM)
	fmt.Print(item.binding, DELIM, item.pages, " pages", DELIM, item.isbn, DELIM, item.ean, DELIM, item.price, DELIM, item.priceCurrency)
	fmt.Println()
}
开发者ID:rlaakso,项目名称:amzn,代码行数:32,代码来源:item-lookup.go

示例8: 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

示例9: TestHTML

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

示例10: 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

示例11: 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

示例12: 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

示例13: getTitusCsvLink

func getTitusCsvLink(root *xmlpath.Node) (string, error) {
	path := xmlpath.MustCompile(titusCsvXpath)
	csvLink, ok := path.String(root)
	if ok {
		return TitusCgiBaseUrl + "/" + csvLink, nil
	} else {
		return "", fmt.Errorf("could not find xpath %s", titusCsvXpath)
	}
}
开发者ID:80nashi,项目名称:windmon,代码行数:9,代码来源:titus.go

示例14: 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

示例15: 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


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