func (xmlNode *XmlNode) SetNsAttr(name, value string, xmlNs *XmlNs) (val string) { val = value if xmlNode.NodeType() != XML_ELEMENT_NODE { return } nameBytes := GetCString([]byte(name)) namePtr := unsafe.Pointer(&nameBytes[0]) valueBytes := GetCString([]byte(value)) valuePtr := unsafe.Pointer(&valueBytes[0]) if xmlNs == nil { C.xmlSetProp(xmlNode.Ptr, (*C.xmlChar)(namePtr), (*C.xmlChar)(valuePtr)) } else { C.xmlSetNsProp(xmlNode.Ptr, xmlNs.Ptr, (*C.xmlChar)(namePtr), (*C.xmlChar)(valuePtr)) } return }
// The namespace should already be declared and in-scope when SetNsAttr is called. // This restriction will be lifted in a future version. func (xmlNode *XmlNode) SetNsAttr(href, name, value string) (val string) { val = value if xmlNode.NodeType() != XML_ELEMENT_NODE { return } nameBytes := GetCString([]byte(name)) namePtr := unsafe.Pointer(&nameBytes[0]) valueBytes := GetCString([]byte(value)) valuePtr := unsafe.Pointer(&valueBytes[0]) hrefBytes := GetCString([]byte(href)) hrefPtr := unsafe.Pointer(&hrefBytes[0]) ns := C.xmlSearchNsByHref((*C.xmlDoc)(xmlNode.Document.DocPtr()), xmlNode.Ptr, (*C.xmlChar)(hrefPtr)) if ns == nil { return } C.xmlSetNsProp(xmlNode.Ptr, ns, (*C.xmlChar)(namePtr), (*C.xmlChar)(valuePtr)) return }