當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。