本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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"])
}
示例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)
}
}
}
}
}
示例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
//.........這裏部分代碼省略.........