本文整理汇总了Golang中github.com/beevik/etree.Document.FindElements方法的典型用法代码示例。如果您正苦于以下问题:Golang Document.FindElements方法的具体用法?Golang Document.FindElements怎么用?Golang Document.FindElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/beevik/etree.Document
的用法示例。
在下文中一共展示了Document.FindElements方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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)
}
}
}
}
}
示例4: doFile
//.........这里部分代码省略.........
state.inMetadata = true
var src string
for _, e := range t.Attr {
if e.Name.Local == "src" {
src = e.Value
break
}
}
if src != "" {
if cfg.Meta_src != "" {
fmt.Fprintf(fpout, "##META text %s = %s\n", cfg.Meta_src, src)
}
srcs := make([]string, 0, 4)
if dirname != "" {
srcs = append(srcs, filepath.Join(dirname, src+".xml"), filepath.Join(dirname, src))
}
srcs = append(srcs, src+".xml", src)
for i, src := range srcs {
doc = etree.NewDocument()
err := doc.ReadFromFile(filepath.Join(cfg.Meta_dir, src))
if err == nil {
break
}
if i == len(srcs)-1 {
x(err)
}
}
for _, item := range fixed {
found := false
for _, t := range doc.FindElements(cfg.Items[item].XPath) {
value := 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) {
found = true
fmt.Fprintf(fpout, "##META %s %s = %s\n", cfg.Items[item].Type, item, value)
}
}
if !found {
fmt.Fprintf(os.Stderr, "Niet gevonden in %s voor (%s) %s\n", currentfile, cfg.Items[item].Type, item)
fmt.Fprintf(fpout, "##META %s %s =\n", cfg.Items[item].Type, item)
}
}
hasMeta = true
fixedDone = true
}
case "meta":
meta = ""
for _, e := range t.Attr {
if e.Name.Local == "id" {
meta = e.Value
break
}
}
state.inMeta = native_use[meta]
case "foreign-data":
if !state.inMetadata {
x(fmt.Errorf("Invalid tag <foreign-data>"))
}