func (n *Element) getAttributeNode(name string) (*C.xmlAttr, error) { prop := C.xmlHasNsProp(n.ptr, stringToXmlChar(name), nil) if prop != nil { prefix, local := splitPrefixLocal(name) if local != "" { ns := C.xmlSearchNs(n.ptr.doc, n.ptr, stringToXmlChar(prefix)) if ns != nil { prop = C.xmlHasNsProp(n.ptr, stringToXmlChar(local), ns.href) } } } if prop == nil || XmlNodeType(prop._type) != AttributeNode { return nil, errors.New("attribute not found") } return prop, nil }
// Return the attribute node, or nil if the attribute does not exist. func (xmlNode *XmlNode) Attribute(name string) (attribute *AttributeNode) { if xmlNode.NodeType() != XML_ELEMENT_NODE { return } nameBytes := GetCString([]byte(name)) namePtr := unsafe.Pointer(&nameBytes[0]) attrPtr := C.xmlHasNsProp(xmlNode.Ptr, (*C.xmlChar)(namePtr), nil) if attrPtr == nil { return } else { node := NewNode(unsafe.Pointer(attrPtr), xmlNode.Document) if node, ok := node.(*AttributeNode); ok { attribute = node } } return }