Exemplo n.º 1
0
func TestFindNodeByPos(t *testing.T) {
	x := `<?xml version="1.0" encoding="UTF-8"?><p1 xmlns="http://test" attr1="foo"><p2 xmlns="http://test2" xmlns:test="http://test3" attr2="bar"><p3/>text<p4/></p2></p1>`
	nt := xmltree.MustParseXML(bytes.NewBufferString(x))
	if tree.FindNodeByPos(nt, 5).GetNodeType() != tree.NtElem {
		t.Error("Node 5 not element")
	}
	if tree.FindNodeByPos(nt, 14).GetNodeType() != tree.NtChd {
		t.Error("Node 14 not char data")
	}
	if tree.FindNodeByPos(nt, 4).GetNodeType() != tree.NtAttr {
		t.Error("Node 4 not attribute")
	}
	if tree.FindNodeByPos(nt, 3).GetNodeType() != tree.NtNs {
		t.Error("Node 3 not namespace")
	}
	if tree.FindNodeByPos(nt, 19) != nil {
		t.Error("Invalid node returned")
	}
}
Exemplo n.º 2
0
func TestMarshalErr(t *testing.T) {
	x := `<?xml version="1.0" encoding="UTF-8"?><p1><p2/></p1>`
	n := xmltree.MustParseXML(bytes.NewBufferString(x))
	f := tree.FindNodeByPos(n, 3).(*xmlele.XMLEle)
	f.Name.Local = ""
	buf := &bytes.Buffer{}
	err := Marshal(n, buf)
	if err == nil {
		t.Error("No error")
	}
}