本文整理汇总了Golang中github.com/beevik/etree.NewDocument函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDocument函数的具体用法?Golang NewDocument怎么用?Golang NewDocument使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDocument函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: TestLibirtPluginNet
func TestLibirtPluginNet(t *testing.T) {
Convey("List interfaces", t, func() {
buf, err := ioutil.ReadFile("./test_domain.xml")
if err != nil {
panic(err)
}
domXMLStr := string(buf)
domXML := etree.NewDocument()
domXML.ReadFromString(domXMLStr)
data := listInterfaces(domXML)
So(data, ShouldResemble, []string{"tap88709cbd-90"})
})
Convey("List interfaces with no net interface", t, func() {
buf, err := ioutil.ReadFile("./test_domain_2.xml")
if err != nil {
panic(err)
}
domXMLStr := string(buf)
domXML := etree.NewDocument()
domXML.ReadFromString(domXMLStr)
data := listInterfaces(domXML)
So(data, ShouldResemble, []string{})
})
}
开发者ID:geauxvirtual,项目名称:snap-plugin-collector-libvirt,代码行数:27,代码来源:net_test.go
示例3: TestLibirtPluginDisk
func TestLibirtPluginDisk(t *testing.T) {
Convey("List disks", t, func() {
buf, err := ioutil.ReadFile("./test_domain.xml")
if err != nil {
panic(err)
}
domXMLStr := string(buf)
domXML := etree.NewDocument()
domXML.ReadFromString(domXMLStr)
data := listDisks(domXML)
So(data, ShouldResemble, []string{"vda"})
})
Convey("List disks with no disk device", t, func() {
buf, err := ioutil.ReadFile("./test_domain_2.xml")
if err != nil {
panic(err)
}
domXMLStr := string(buf)
domXML := etree.NewDocument()
domXML.ReadFromString(domXMLStr)
data := listDisks(domXML)
So(data, ShouldResemble, []string{})
})
}
开发者ID:geauxvirtual,项目名称:snap-plugin-collector-libvirt,代码行数:27,代码来源:disk_test.go
示例4: ExamplePath
func ExamplePath() {
doc := etree.NewDocument()
doc.ReadFromString(xml)
for _, e := range doc.FindElements(".//book[author='Charles Dickens']") {
book := etree.NewDocument()
book.SetRoot(e.Copy())
book.Indent(2)
book.WriteTo(os.Stdout)
}
// Output:
// <book>
// <title>Great Expectations</title>
// <author>Charles Dickens</author>
// </book>
}
开发者ID:suntong,项目名称:lang,代码行数:15,代码来源:et_example.go
示例5: ExampleDocument_creating
// Create an etree Document, add XML entities to it, and serialize it
// to stdout.
func ExampleDocument_creating() {
doc := etree.NewDocument()
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
doc.CreateProcInst("xml-stylesheet", `type="text/xsl" href="style.xsl"`)
people := doc.CreateElement("People")
people.CreateComment("These are all known people")
jon := people.CreateElement("Person")
jon.CreateAttr("name", "Jon O'Reilly")
sally := people.CreateElement("Person")
sally.CreateAttr("name", "Sally")
doc.Indent(2)
doc.WriteTo(os.Stdout)
// Output:
// <?xml version="1.0" encoding="UTF-8"?>
// <?xml-stylesheet type="text/xsl" href="style.xsl"?>
// <People>
// <!--These are all known people-->
// <Person name="Jon O'Reilly"/>
// <Person name="Sally"/>
// </People>
}
开发者ID:hzmnet,项目名称:etree,代码行数:27,代码来源:example_test.go
示例6: validateSignature
func (v *Validator) validateSignature() error {
doc := etree.NewDocument()
doc.SetRoot(v.signedInfo.Copy())
signedInfo, err := doc.WriteToString()
if err != nil {
return err
}
canonSignedInfo, err := v.canonAlgorithm.Process(signedInfo, "")
if err != nil {
return err
}
b64, err := base64.StdEncoding.DecodeString(v.sigValue)
if err != nil {
return err
}
sig := []byte(b64)
v.signingCert = x509.Certificate{}
for _, cert := range v.Certificates {
err := cert.CheckSignature(v.sigAlgorithm, []byte(canonSignedInfo), sig)
if err == nil {
v.signingCert = cert
return nil
}
}
return errors.New("signedxml: Calculated signature does not match the " +
"SignatureValue provided")
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:31,代码来源:validator.go
示例7: XML
// XML is building xml.
func (su *sitemapURL) XML() []byte {
doc := etree.NewDocument()
url := doc.CreateElement("url")
SetBuilderElementValue(url, su.data.URLJoinBy("loc", "host", "loc"), "loc")
SetBuilderElementValue(url, su.data, "expires")
SetBuilderElementValue(url, su.data, "mobile")
if !SetBuilderElementValue(url, su.data, "changefreq") {
changefreq := url.CreateElement("changefreq")
changefreq.SetText("weekly")
}
if !SetBuilderElementValue(url, su.data, "priority") {
priority := url.CreateElement("priority")
priority.SetText("0.5")
}
if !SetBuilderElementValue(url, su.data, "lastmod") {
lastmod := url.CreateElement("lastmod")
lastmod.SetText(time.Now().Format(time.RFC3339))
}
SetBuilderElementValue(url, su.data, "news")
SetBuilderElementValue(url, su.data, "image")
SetBuilderElementValue(url, su.data, "video")
SetBuilderElementValue(url, su.data, "geo")
buf := &bytes.Buffer{}
// doc.Indent(2)
doc.WriteTo(buf)
return buf.Bytes()
}
开发者ID:Staylett,项目名称:go-sitemap-generator,代码行数:33,代码来源:builder_url.go
示例8: ExampleAddElement
func ExampleAddElement() {
docR := readXml(bookstore)
root := docR.SelectElement("bookstore")
docA := etree.NewDocument()
docA.ReadFromString(xml)
docA.Indent(2)
docA.WriteTo(os.Stdout)
// To directly add docA under root
//root.AddElement(docA.Root())
// To add all book nodes under docA to root
for _, e := range docA.FindElements(".//book") {
// add (e) under root
root.AddElement(e)
}
fmt.Println()
docR.Indent(2)
docR.WriteTo(os.Stdout)
fmt.Println()
docA.Indent(2)
docA.WriteTo(os.Stdout)
}
开发者ID:suntong,项目名称:lang,代码行数:26,代码来源:et_example.go
示例9: NodeSearch
func NodeSearch(filename string) {
doc := etree.NewDocument()
if err := doc.ReadFromFile(filename); err != nil {
panic(err)
}
aut := Person{Fname: "ПЕТР", Mname: "ПЕТРОВИЧ", Lname: "ПЕТУХОВ"}
root := doc.FindElement("./FictionBook/description/title-info")
fmt.Println("ROOT element:", root.Tag)
aut.CreateXml(root)
// doc := xmlx.New()
fo, err := os.Create("output.fb2")
if err != nil {
panic(err)
}
doc.IndentTabs()
doc.WriteTo(fo)
// if err := doc.LoadFile(filename, nil); err != nil {
// fmt.Printf("LoadFile(): %s", err)
// return
// }
// node := doc.SelectNode("http://www.gribuser.ru/xml/fictionbook/2.0", "middle-name")
// if node == nil {
// fmt.Printf("SelectNode(): No node found.")
// return
// }
// // addTo := node.Parent
// fmt.Printf("%v\n", node.Type)
}
开发者ID:ppoloskov,项目名称:renamefb2books,代码行数:35,代码来源:readxml.go
示例10: TestMobileSitemaps
func TestMobileSitemaps(t *testing.T) {
doc := etree.NewDocument()
root := doc.CreateElement("root")
data := URL{"loc": "/mobile", "mobile": true}
expect := []byte(`
<root>
<loc>/mobile</loc>
<mobile:mobile/>
</root>`)
SetBuilderElementValue(root, data.URLJoinBy("loc", "host", "loc"), "loc")
SetBuilderElementValue(root, data, "mobile")
buf := &bytes.Buffer{}
doc.WriteTo(buf)
mdata, _ := mxj.NewMapXml(buf.Bytes())
mexpect, _ := mxj.NewMapXml(expect)
if !reflect.DeepEqual(mdata, mexpect) {
t.Error(`Failed to generate sitemap xml thats deferrent output value in URL type`)
}
}
开发者ID:yaotian,项目名称:go-sitemap,代码行数:25,代码来源:builder_url_test.go
示例11: TestImageSitemaps
func TestImageSitemaps(t *testing.T) {
doc := etree.NewDocument()
root := doc.CreateElement("root")
data := URL{"loc": "/images", "image": []URL{
{"loc": "http://www.example.com/image.png", "title": "Image"},
{"loc": "http://www.example.com/image1.png", "title": "Image1"},
}}
expect := []byte(`
<root>
<image:image>
<image:loc>http://www.example.com/image.png</image:loc>
<image:title>Image</image:title>
</image:image>
<image:image>
<image:loc>http://www.example.com/image1.png</image:loc>
<image:title>Image1</image:title>
</image:image>
</root>`)
SetBuilderElementValue(root, data, "image")
buf := &bytes.Buffer{}
doc.WriteTo(buf)
mdata, _ := mxj.NewMapXml(buf.Bytes())
mexpect, _ := mxj.NewMapXml(expect)
if !reflect.DeepEqual(mdata, mexpect) {
t.Error(`Failed to generate sitemap xml thats deferrent output value in URL type`)
}
}
开发者ID:Staylett,项目名称:go-sitemap-generator,代码行数:31,代码来源:builder_url_test.go
示例12: init
func init() {
log.SetLevel(log.DebugLevel)
// do a deep copy for etree of job config.xml
JobConfig = etree.NewDocument()
if err := JobConfig.ReadFromFile(BaseCfg); err != nil {
log.Errorf(err.Error())
return
}
/*
// connect mongodb
MgoDB = getMongoDB()
if MgoDB == nil {
return
}
*/
// session uses memory
GlobalSessions, _ = session.NewManager(
"memory", `{"cookieName":"sessionId","enableSetCookie":true,"gclifetime":30,"ProviderConfig":"{\"cookieName\":\"sessionId\",\"securityKey\":\"beegocookiehashkey\"}"}`)
go GlobalSessions.GC()
JenkinsClient = make(map[string]*gojenkins.Jenkins)
/*
for {
JenkinsClient = getJenkinsClient()
if JenkinsClient == nil {
time.Sleep(10)
continue
} else {
break
}
}
*/
}
开发者ID:zhanglianx111,项目名称:lasa,代码行数:32,代码来源:handlers.go
示例13: main
func main() {
doc := etree.NewDocument()
if err := doc.ReadFromFile("et_dump.xml"); err != nil {
panic(err)
}
doc.Indent(2)
doc.WriteTo(os.Stdout)
}
开发者ID:suntong,项目名称:lang,代码行数:9,代码来源:et_dump.go
示例14: NewValidator
// NewValidator returns a *Validator for the XML provided
func NewValidator(xml string) (*Validator, error) {
doc := etree.NewDocument()
err := doc.ReadFromString(xml)
if err != nil {
return nil, err
}
v := &Validator{signatureData: signatureData{xml: doc}}
return v, nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:10,代码来源:validator.go
示例15: NewSigner
// NewSigner returns a *Signer for the XML provided
func NewSigner(xml string) (*Signer, error) {
doc := etree.NewDocument()
err := doc.ReadFromString(xml)
if err != nil {
return nil, err
}
s := &Signer{signatureData: signatureData{xml: doc}}
return s, nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:10,代码来源:signer.go
示例16: getIDPEndpointFromMetadata
func (c *Config) getIDPEndpointFromMetadata(body string) string {
doc := etree.NewDocument()
err := doc.ReadFromString(body)
if err != nil {
panic(err)
}
endpointElement := doc.FindElement("//PassiveRequestorEndpoint/EndpointReference/Address[1]")
if endpointElement == nil {
panic(errors.New("go-wsfed: unable to find Passive Requestor Endpoint in metadata"))
}
return endpointElement.Text()
}
开发者ID:ma314smith,项目名称:go-wsfed,代码行数:12,代码来源:config.go
示例17: 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
示例18: loadPrefixList
func (e *ExclusiveCanonicalization) loadPrefixList(transformXML string) {
if transformXML != "" {
tDoc := etree.NewDocument()
tDoc.ReadFromString(transformXML)
inclNSNode := tDoc.Root().SelectElement("InclusiveNamespaces")
if inclNSNode != nil {
prefixList := inclNSNode.SelectAttrValue("PrefixList", "")
if prefixList != "" {
e.inclusiveNamespacePrefixList = strings.Split(prefixList, " ")
}
}
}
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:13,代码来源:exclusivecanonicalization.go
示例19: setSignature
func (s *Signer) setSignature() error {
doc := etree.NewDocument()
doc.SetRoot(s.signedInfo.Copy())
signedInfo, err := doc.WriteToString()
if err != nil {
return err
}
canonSignedInfo, err := s.canonAlgorithm.Process(signedInfo, "")
if err != nil {
return err
}
var hashed, signature []byte
//var h1, h2 *big.Int
signingAlgorithm, ok := signingAlgorithms[s.sigAlgorithm]
if !ok {
return errors.New("signedxml: unsupported algorithm")
}
hasher := signingAlgorithm.hash.New()
hasher.Write([]byte(canonSignedInfo))
hashed = hasher.Sum(nil)
switch signingAlgorithm.algorithm {
case "rsa":
signature, err = rsa.SignPKCS1v15(rand.Reader, s.privateKey.(*rsa.PrivateKey), signingAlgorithm.hash, hashed)
/*
case "dsa":
h1, h2, err = dsa.Sign(rand.Reader, s.privateKey.(*dsa.PrivateKey), hashed)
case "ecdsa":
h1, h2, err = ecdsa.Sign(rand.Reader, s.privateKey.(*ecdsa.PrivateKey), hashed)
*/
}
if err != nil {
return err
}
// DSA and ECDSA has not been validated
/*
if signature == nil && h1 != nil && h2 != nil {
signature = append(h1.Bytes(), h2.Bytes()...)
}
*/
b64 := base64.StdEncoding.EncodeToString(signature)
sigValueElement := s.signature.SelectElement("SignatureValue")
sigValueElement.SetText(b64)
return nil
}
开发者ID:ma314smith,项目名称:signedxml,代码行数:51,代码来源:signer.go
示例20: TestJustSetLocElementAndThenItNeedsCompleteValues
func TestJustSetLocElementAndThenItNeedsCompleteValues(t *testing.T) {
smu, err := NewSitemapURL(URL{"loc": "path", "host": "http://example.com"})
if err != nil {
t.Fatalf(`Fatal to validate! This is a critical error: %s`, err)
}
doc := etree.NewDocument()
doc.ReadFromBytes(smu.XML())
var elm *etree.Element
url := doc.SelectElement("url")
elm = url.SelectElement("loc")
if elm == nil {
t.Errorf(`Failed to generate xml that loc element is blank: %s`, elm)
}
if elm != nil && elm.Text() != "http://example.com/path" {
t.Errorf(`Failed to generate xml thats deferrent value in loc element: %s`, elm.Text())
}
elm = url.SelectElement("priority")
if elm == nil {
t.Errorf(`Failed to generate xml that priority element is nil: %s`, elm)
}
if elm != nil && elm.Text() != "0.5" {
t.Errorf(`Failed to generate xml thats deferrent value in priority element: %s`, elm.Text())
}
elm = url.SelectElement("changefreq")
if elm == nil {
t.Errorf(`Failed to generate xml that changefreq element is nil: %s`, elm)
}
if elm != nil && elm.Text() != "weekly" {
t.Errorf(`Failed to generate xml thats deferrent value in changefreq element: %s`, elm.Text())
}
elm = url.SelectElement("lastmod")
if elm == nil {
t.Errorf(`Failed to generate xml that lastmod element is nil: %s`, elm)
}
if elm != nil {
if _, err := time.Parse(time.RFC3339, elm.Text()); err != nil {
t.Errorf(`Failed to generate xml thats failed to parse datetime in lastmod element: %s`, err)
}
}
}
开发者ID:Staylett,项目名称:go-sitemap-generator,代码行数:47,代码来源:builder_url_test.go
注:本文中的github.com/beevik/etree.NewDocument函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论