本文整理匯總了Golang中xml/dom.ParseString函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseString函數的具體用法?Golang ParseString怎麽用?Golang ParseString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDocumentCreateElement
func TestDocumentCreateElement(t *testing.T) {
d, _ := dom.ParseString(`<foo></foo>`)
ne := d.CreateElement("child")
if ne.NodeName() != "child" {
t.Errorf("document.CreateNode('child') did not create a <child> Element")
}
}
示例2: TestDocumentElementTagName
func TestDocumentElementTagName(t *testing.T) {
d, _ := dom.ParseString("<foo></foo>")
root := d.DocumentElement().(dom.Element)
if root.TagName() != "foo" {
t.Errorf("Element.tagName not set correctly")
}
}
示例3: TestNodeDocumentChildNodeIsRoot
func TestNodeDocumentChildNodeIsRoot(t *testing.T) {
d, _ := dom.ParseString(`<foo></foo>`)
root := d.DocumentElement().(dom.Node)
if d.ChildNodes().Item(0) != root {
t.Errorf("document.ChildNodes().Item(0) is not the documentElement")
}
}
示例4: TestElementNodeType
// Element.nodeType should be 1
func TestElementNodeType(t *testing.T) {
d, _ := dom.ParseString("<foo></foo>")
root := d.DocumentElement()
if root.NodeType() != 1 {
t.Errorf("Element.nodeType not equal to 1")
}
}
示例5: TestElementNodeValue
func TestElementNodeValue(t *testing.T) {
d, _ := dom.ParseString("<foo></foo>")
root := d.DocumentElement()
if root.NodeValue() != "" {
t.Errorf("Element.nodeValue not empty")
}
}
示例6: TestElementGetAttribute
func TestElementGetAttribute(t *testing.T) {
d, _ := dom.ParseString("<foo bar='baz'></foo>")
root := d.DocumentElement()
if root.GetAttribute("bar") != "baz" {
t.Errorf("Element.getAttribute() did not return the attribute value")
}
}
示例7: TestAttributesNamedNodeMapSetNamedItem
func TestAttributesNamedNodeMapSetNamedItem(t *testing.T) {
d, _ := dom.ParseString(`<parent attr1="val1" attr2="val2"></parent>`)
r := d.DocumentElement()
attrs := r.Attributes()
attr2 := d.CreateAttribute("attr2")
attr2Returned := attrs.SetNamedItem(attr2)
if attr2Returned == nil {
t.Errorf("NamedNodeMap.setNamedItem(attr2) returned nil")
}
if attr2Returned == attr2 {
t.Errorf("NamedNodeMap.setNamedItem(attr2) returned attr2")
}
if r.GetAttribute("attr2") != "" {
t.Errorf("attr2 was not empty")
}
attr3 := d.CreateAttribute("attr3")
attr3Returned := attrs.SetNamedItem(attr3)
if attr3Returned != nil {
t.Errorf("NamedNodeMap.setNamedItem(attr3) did not return nil")
}
if r.GetAttribute("attr3") != "" {
t.Errorf("attr3 was not empty")
}
if r.Attributes().Length() != 3 {
t.Errorf("Did not have 3 attributes")
}
}
示例8: TestDocumentElementIsAnElement
// Document.documentElement should return an object implementing Element
func TestDocumentElementIsAnElement(t *testing.T) {
d, _ := dom.ParseString("<foo></foo>")
n, ok := (d.DocumentElement()).(dom.Element)
if !ok || n.NodeType() != 1 {
t.Errorf("Document.documentElement did not return an Element")
}
}
示例9: TestElementRemoveAttribute
func TestElementRemoveAttribute(t *testing.T) {
d, _ := dom.ParseString(`<parent attr="val"/>`)
r := d.DocumentElement()
r.RemoveAttribute("attr")
if r.GetAttribute("attr") != "" {
t.Errorf("Element.RemoveAttribute() did not remove the attribute, GetAttribute() returns '%s'", r.GetAttribute("attr"))
}
}
示例10: TestCharacterDataGetData
func TestCharacterDataGetData(t *testing.T) {
d, _ := dom.ParseString(`<parent>foo</parent>`)
r := d.DocumentElement()
cdata := r.ChildNodes().Item(0).(dom.Text)
if cdata.GetData() != "foo" {
t.Errorf("CharacterData.data not correct")
}
}
示例11: TestTextNodeName
func TestTextNodeName(t *testing.T) {
d, _ := dom.ParseString(`<parent>mom</parent>`)
r := d.DocumentElement()
txt := r.ChildNodes().Item(0)
if txt.NodeName() != "#text" {
t.Errorf("Did not get #text for nodeName of a text node")
}
}
示例12: TestAttrGetValue
func TestAttrGetValue(t *testing.T) {
d, _ := dom.ParseString(`<parent attr1="val1"/>`)
r := d.DocumentElement()
if r.Attributes().Item(0).(dom.Attr).GetValue() != "val1" {
t.Errorf("Attr.GetValue() did not return the proper value")
}
}
示例13: TestAttrNodeName
func TestAttrNodeName(t *testing.T) {
d, _ := dom.ParseString(`<parent attr1="val"/>`)
r := d.DocumentElement()
if r.Attributes().Item(0).NodeName() != "attr1" {
t.Errorf("Element.attributes().item(0).NodeName() did not return the proper value")
}
}
示例14: TestCharacterDataLength
func TestCharacterDataLength(t *testing.T) {
d, _ := dom.ParseString(`<parent>foo</parent>`)
r := d.DocumentElement()
cdata := r.ChildNodes().Item(0).(dom.Text)
if cdata.Length() != 3 {
t.Errorf("CharacterData.length not correct")
}
}
示例15: TestTextNodeType
func TestTextNodeType(t *testing.T) {
d, _ := dom.ParseString(`<parent>mom</parent>`)
r := d.DocumentElement()
txt := r.ChildNodes().Item(0)
if txt.NodeType() != 3 {
t.Errorf("Did not get the correct node type for a text node")
}
}