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


Golang dom.ParseString函数代码示例

本文整理汇总了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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:7,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:7,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:7,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例5: TestElementNodeValue

func TestElementNodeValue(t *testing.T) {
	d, _ := dom.ParseString("<foo></foo>")
	root := d.DocumentElement()
	if root.NodeValue() != "" {
		t.Errorf("Element.nodeValue not empty")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:7,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:7,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:29,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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"))
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go

示例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")
	}
}
开发者ID:grmartin,项目名称:godom,代码行数:8,代码来源:dom_test.go


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