本文整理匯總了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)
}
}
}