本文整理汇总了Golang中github.com/beevik/etree.Element.Text方法的典型用法代码示例。如果您正苦于以下问题:Golang Element.Text方法的具体用法?Golang Element.Text怎么用?Golang Element.Text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/beevik/etree.Element
的用法示例。
在下文中一共展示了Element.Text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestJustSetLocElement
func TestJustSetLocElement(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())
}
}
示例2: TestSetNilValue
func TestSetNilValue(t *testing.T) {
smu, err := NewSitemapURL(&Options{}, URL{"loc": "path", "priority": nil, "changefreq": nil, "lastmod": nil, "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 must be nil: %s`, elm)
}
elm = url.SelectElement("changefreq")
if elm != nil {
t.Errorf(`Failed to generate xml that changefreq element must be nil: %s`, elm)
}
elm = url.SelectElement("lastmod")
if elm != nil {
t.Errorf(`Failed to generate xml that lastmod element must be nil: %s`, elm)
}
}
示例3: 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)
}
}
}