Exemplo n.º 1
0
// xmlNewDocNode
func (doc *Document) NewNode(ns *Namespace, name string, content string) *Node {
	ptrn := C.CString(name)
	defer C.free_string(ptrn)
	ptrc := C.CString(content)
	defer C.free_string(ptrc)
	if ns != nil {
		return makeNode(C.xmlNewDocNode(doc.Ptr, ns.Ptr, C.to_xmlcharptr(ptrn), C.to_xmlcharptr(ptrc)))
	}
	return makeNode(C.xmlNewDocNode(doc.Ptr, nil, C.to_xmlcharptr(ptrn), C.to_xmlcharptr(ptrc)))
}
Exemplo n.º 2
0
func (d *Document) CreateElementNS(nsuri, name string) (*Element, error) {
	if C.MY_test_node_name(stringToXmlChar(name)) == 0 {
		return nil, ErrInvalidNodeName
	}

	i := strings.IndexByte(name, ':')
	nsuriDup := stringToXmlChar(nsuri)
	prefix := stringToXmlChar(name[:i])
	localname := stringToXmlChar(name[i+1:])

	ns := C.xmlNewNs(nil, nsuriDup, prefix)
	newNode := C.xmlNewDocNode(d.ptr, ns, localname, nil)
	newNode.nsDef = ns

	return wrapElement((*C.xmlElement)(unsafe.Pointer(newNode))), nil
}
Exemplo n.º 3
0
// CreateElementNS Create an element with the given namespace
func (xp *Xp) createElementNS(prefix, element string, context *C.xmlNode, before *C.xmlNode) (newcontext *C.xmlNode) {

	ns := C.xmlNewNs(nil, namespaces[prefix].ns_uri, namespaces[prefix].prefix) // candidate for cache ...
	if ns == nil {
		panic("ns is nil")
	}
	celement := unsafe.Pointer(C.CString(element))
	newelement := C.xmlNewDocNode(xp.doc, ns, (*C.xmlChar)(celement), nil)
	C.free(celement)

	if before != nil {
		newcontext = C.xmlAddPrevSibling(before, newelement)
	} else {
		if context == nil {
			context = C.xmlDocGetRootElement(xp.doc)
		}
		newcontext = C.xmlAddChild(context, newelement)
	}
	return
}