本文整理匯總了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>"))
}