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

Golang etree.Document类代码示例

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

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



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

示例1: getReferencedXML

func getReferencedXML(reference *etree.Element, inputDoc *etree.Document) (outputDoc *etree.Document, err error) {
	uri := reference.SelectAttrValue("URI", "")
	uri = strings.Replace(uri, "#", "", 1)
	// populate doc with the referenced xml from the Reference URI
	if uri == "" {
		outputDoc = inputDoc
	} else {
		path := fmt.Sprintf(".//[@ID='%s']", uri)
		e := inputDoc.FindElement(path)
		if e != nil {
			outputDoc = etree.NewDocument()
			outputDoc.SetRoot(e.Copy())
		} else {
			// SAML v1.1 Assertions use AssertionID
			path := fmt.Sprintf(".//[@AssertionID='%s']", uri)
			e := inputDoc.FindElement(path)
			if e != nil {
				outputDoc = etree.NewDocument()
				outputDoc.SetRoot(e.Copy())
			}
		}
	}

	if outputDoc == nil {
		return nil, errors.New("signedxml: unable to find refereced xml")
	}

	return outputDoc, nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:29,代码来源:signedxml.go


示例2: listInterfaces

func listInterfaces(domXML *etree.Document) []string {
	networkInterfaces := []string{}
	for _, t := range domXML.FindElements("//domain/devices/interface/target") {
		for _, i := range t.Attr {
			networkInterfaces = append(networkInterfaces, i.Value)
		}

	}
	return networkInterfaces
}
开发者ID:geauxvirtual,项目名称:snap-plugin-collector-libvirt,代码行数:10,代码来源:net.go


示例3: listDisks

func listDisks(domXML *etree.Document) []string {
	disks := []string{}
	for _, t := range domXML.FindElements("//domain/devices/disk[@device='disk']/target") {
		for _, i := range t.Attr {
			if i.Key == "dev" {
				disks = append(disks, i.Value)
			}
		}
	}
	return disks
}
开发者ID:geauxvirtual,项目名称:snap-plugin-collector-libvirt,代码行数:11,代码来源:disk.go


示例4: removeTokenFromDocument

func removeTokenFromDocument(token etree.Token, d *etree.Document) *etree.Token {
	for i, t := range d.Child {
		if t == token {
			d.Child = append(d.Child[0:i], d.Child[i+1:]...)
			return &t
		}
	}
	return nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:9,代码来源:exclusivecanonicalization.go


示例5: processTransform

func processTransform(transform *etree.Element,
	docIn *etree.Document) (docOut *etree.Document, err error) {

	transformAlgoURI := transform.SelectAttrValue("Algorithm", "")
	if transformAlgoURI == "" {
		return nil, errors.New("signedxml: unable to find Algorithm in Transform")
	}

	transformAlgo, ok := CanonicalizationAlgorithms[transformAlgoURI]
	if !ok {
		return nil, fmt.Errorf("signedxml: unable to find matching transform"+
			"algorithm for %s in CanonicalizationAlgorithms", transformAlgoURI)
	}

	var transformContent string

	if transform.ChildElements() != nil {
		tDoc := etree.NewDocument()
		tDoc.SetRoot(transform.Copy())
		transformContent, err = tDoc.WriteToString()
		if err != nil {
			return nil, err
		}
	}

	docString, err := docIn.WriteToString()
	if err != nil {
		return nil, err
	}

	docString, err = transformAlgo.Process(docString, transformContent)
	if err != nil {
		return nil, err
	}

	docOut = etree.NewDocument()
	docOut.ReadFromString(docString)

	return docOut, nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:40,代码来源:signedxml.go


示例6: calculateHash

func calculateHash(reference *etree.Element, doc *etree.Document) (string, error) {
	digestMethodElement := reference.SelectElement("DigestMethod")
	if digestMethodElement == nil {
		return "", errors.New("signedxml: unable to find DigestMethod")
	}

	digestMethodURI := digestMethodElement.SelectAttrValue("Algorithm", "")
	if digestMethodURI == "" {
		return "", errors.New("signedxml: unable to find Algorithm in DigestMethod")
	}

	digestAlgo, ok := hashAlgorithms[digestMethodURI]
	if !ok {
		return "", fmt.Errorf("signedxml: unable to find matching hash"+
			"algorithm for %s in hashAlgorithms", digestMethodURI)
	}

	doc.WriteSettings.CanonicalEndTags = true
	doc.WriteSettings.CanonicalText = true
	doc.WriteSettings.CanonicalAttrVal = true

	h := digestAlgo.New()
	docBytes, err := doc.WriteToBytes()
	if err != nil {
		return "", err
	}

	//ioutil.WriteFile("C:/Temp/SignedXML/Suspect.xml", docBytes, 0644)
	//s, _ := doc.WriteToString()
	//logger.Println(s)

	h.Write(docBytes)
	d := h.Sum(nil)
	calculatedValue := base64.StdEncoding.EncodeToString(d)

	return calculatedValue, nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:37,代码来源:signedxml.go


示例7: updateJobConfigXml

func updateJobConfigXml(doc *etree.Document, cfg map[string]string) {
	eDesc := doc.FindElement(Root + Description)
	eDesc.SetText(cfg["desc"])

	eRepoURL := doc.FindElement(Root + Scm + UsrRemoteConfigs + HudsonPluginsGitUserRemoteConfig + Url)
	eRepoURL.SetText(cfg["repositryurl"])

	eCredentialsid := doc.FindElement(Root + Scm + UsrRemoteConfigs + HudsonPluginsGitUserRemoteConfig + CredentialsId)
	eCredentialsid.SetText(cfg["credentialsid"])

	eBranchesToBuild := doc.FindElement(Root + Scm + Branches + HudsonPluginsGitBranchSpec + Name)
	eBranchesToBuild.SetText(cfg["branchestobuild"])

	eRepoName := doc.FindElement(Root + Builders + ComCloudbeesDockerpublishDockerBuilder + RepoName)
	eRepoName.SetText(cfg["repositryname"])

	eTag := doc.FindElement(Root + Builders + ComCloudbeesDockerpublishDockerBuilder + RepoTag)
	eTag.SetText(cfg["tag"])

	eDockerHostUri := doc.FindElement(Root + Builders + ComCloudbeesDockerpublishDockerBuilder + Server + Uri)
	eDockerHostUri.SetText(cfg["dockerhosturi"])

	eDockerRegistryUrl := doc.FindElement(Root + Builders + ComCloudbeesDockerpublishDockerBuilder + Registry + Url)
	eDockerRegistryUrl.SetText(cfg["dockerregistryurl"])

	eSkipPush := doc.FindElement(Root + Builders + ComCloudbeesDockerpublishDockerBuilder + SkipPush)
	eSkipPush.SetText(cfg["skippush"])

	eCmd := doc.FindElement(Root + Builders + HudsonTasksShell + Command)
	eCmd.SetText(cfg["command"])

}
开发者ID:zhanglianx111,项目名称:lasa,代码行数:32,代码来源:jobs.go


示例8: doSpeaker

func doSpeaker(speaker string, hasMeta, hasMeta2 bool, values map[string]map[string][]string, doc, doc2 *etree.Document) {
	need_scan := false
	if _, ok := values[speaker]; !ok {
		values[speaker] = make(map[string][]string)
		need_scan = true
	}

	var run_hasMeta bool
	var run_doc *etree.Document
	var run_nonfixed []string
	for run := 0; run < 2; run++ {
		if run == 0 {
			run_hasMeta = hasMeta
			run_doc = doc
			run_nonfixed = nonfixed
		} else {
			run_hasMeta = hasMeta2
			run_doc = doc2
			run_nonfixed = nonfixed2
		}

		if run_hasMeta && len(run_nonfixed) > 0 {
			if need_scan {
				for _, item := range run_nonfixed {
					found := false
					var xp string
					if run == 0 {
						xp = cfg.Items[item].XPath
					} else {
						xp = cfg.Items[item].XPath2
					}
					xpath := strings.Replace(xp, "%speaker%", speaker, -1)
					for _, t := range run_doc.FindElements(xpath) {
						value := strings.TrimSpace(t.Text())
						if cfg.Items[item].hasFilter {
							val, err := vm.Run(fmt.Sprintf("fn[%q](%q);", item, value))
							x(err, "\nRunning function for "+item+":\n"+cfg.Items[item].Filter)
							value = val.String()
						}
						if value != "" && oktype(item, value) {
							if _, ok := values[speaker][item]; !ok {
								values[speaker][item] = make([]string, 0, 1)
							}
							values[speaker][item] = append(values[speaker][item], value)
							found = true
						}
					}
					if !found && speaker != "" {
						fmt.Fprintf(os.Stderr, "Niet gevonden in %s voor (%s) %s, %q\n", currentfile, cfg.Items[item].Type, item, speaker)
					}
				}
			}

			for _, item := range run_nonfixed {
				ii, ok := values[speaker][item]
				if !ok || len(ii) == 0 {
					fmt.Fprintf(fpout, "##META %s %s =\n", cfg.Items[item].Type, item)
					continue
				}
				for _, i := range ii {
					fmt.Fprintf(fpout, "##META %s %s = %s\n", cfg.Items[item].Type, item, i)
				}
			}
		}
	}
}
开发者ID:rug-compling,项目名称:paqu,代码行数:66,代码来源:pqfolia.go


示例9: doFile

func doFile(filename, dirname string) {
	if !strings.HasSuffix(filename, ".xml") {
		return
	}

	fileno++
	lineno := 0

	native_seen = make(map[string]bool)

	if cfg.Output_dir != "" {
		var f string
		if strings.HasSuffix(filename, ".xml") {
			f = filename[:len(filename)-4] + ".txt"
		} else {
			f = filename + ".txt"
		}
		var err error
		fpout, err = os.Create(filepath.Join(cfg.Output_dir, dirname, f))
		x(err)
		defer fpout.Close()
		pathlevel = 0
	}

	if cfg.File_src != "" {
		fmt.Fprintf(fpout, "##META text %s = %s\n", cfg.File_src, filename)
	}

	if cfg.File_path != "" {
		if dirname == "" {
			for i := 0; i < pathlevel; i++ {
				fmt.Fprintf(fpout, "##META text %s%d =\n", cfg.File_path, i+1)
			}
			pathlevel = 0
		} else {
			parts := strings.Split(dirname, string(os.PathSeparator))
			for i, p := range parts {
				fmt.Fprintf(fpout, "##META text %s%d = %s\n", cfg.File_path, i+1, p)
			}
			for i := len(parts); i < pathlevel; i++ {
				fmt.Fprintf(fpout, "##META text %s%d =\n", cfg.File_path, i+1)
			}
			pathlevel = len(parts)
		}
	}

	filename = filepath.Join(dirname, filename)

	fmt.Fprintln(os.Stderr, ">", filename)

	var doc, doc2 *etree.Document
	statestack := make([]State, 1, 10)
	currentspeaker := " oiqoewij doijqowiu98793olj fdowqjoiequ8nf  fke f wf  wejfo  fwoiu92  "
	values := make(map[string]map[string][]string)
	hasMeta := false
	hasMeta2 := false
	fixedDone := false
	fixedDone2 := false
	nativeDone := false

	currentfile = filepath.Join(cfg.Data_dir, filename)
	fpin, err := os.Open(currentfile)
	x(err)
	defer fpin.Close()
	d := xml.NewDecoder(fpin)
	var meta, label string
	text := make([]byte, 0)
	var teller, uttteller uint64
PARSE:
	for {
		offset1 := d.InputOffset()
		tt, err := d.Token()
		if err == io.EOF {
			break
		}
		x(err)

		if t, ok := tt.(xml.StartElement); ok {

			state := statestack[len(statestack)-1]

			hasClass := false
			id := ""
			for _, e := range t.Attr {
				switch e.Name.Local {
				case "speaker":
					state.speaker = e.Value
				case "id":
					id = e.Value
				case "class":
					hasClass = true
				case "auth":
					state.inSkip = true
				}
			}

			switch t.Name.Local {
			case "metadata":
				state.inMetadata = true
				var src string
//.........这里部分代码省略.........
开发者ID:rug-compling,项目名称:paqu,代码行数:101,代码来源:pqfolia.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang etree.Element类代码示例发布时间:2022-05-24
下一篇:
Golang etree.NewDocument函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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