当前位置: 首页>>代码示例>>Golang>>正文


Golang etree.NewDocument函数代码示例

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


在下文中一共展示了NewDocument函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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&apos;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


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