Permalink
Browse files

Merge branch 'my-version-of-pr-726'

  • Loading branch information...
2 parents 2d5dcca + a4bd937 commit 765d8dd70246eaa95c504a7a8eec964a7ada241b @flavorjones flavorjones committed Oct 22, 2012
Showing with 26 additions and 11 deletions.
  1. +26 −11 ext/nokogiri/xml_node.c
View
@@ -699,23 +699,38 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
*
* Get the value for +attribute+
*/
-static VALUE get(VALUE self, VALUE attribute)
+static VALUE get(VALUE self, VALUE rattribute)
{
xmlNodePtr node;
- xmlChar* propstr ;
- VALUE rval ;
- Data_Get_Struct(self, xmlNode, node);
+ xmlChar* value = 0;
+ VALUE rvalue ;
+ char* attribute = 0;
+ char* colon = 0;
+ xmlNsPtr ns;
- if(NIL_P(attribute)) return Qnil;
+ if (NIL_P(rattribute)) return Qnil;
- propstr = xmlGetProp(node, (xmlChar *)StringValuePtr(attribute));
+ Data_Get_Struct(self, xmlNode, node);
+ attribute = strdup(StringValuePtr(rattribute));
+
+ colon = strchr(attribute, ':');
+ if (colon) {
+ (*colon) = 0 ; /* create two null-terminated strings of the prefix and attribute name */
+ ns = xmlSearchNs(node->doc, node, (const xmlChar *)(attribute)); /* here attribute points to the prefix */
+ if (ns) {
+ value = xmlGetNsProp(node, (xmlChar*)(colon+1), ns->href); /* here colon+1 points to the attribute name */
+ }
+ } else {
+ value = xmlGetNoNsProp(node, (xmlChar*)attribute);
+ }
- if(!propstr) return Qnil;
+ free(attribute);
+ if (!value) return Qnil;
- rval = NOKOGIRI_STR_NEW2(propstr);
+ rvalue = NOKOGIRI_STR_NEW2(value);
+ xmlFree(value);
- xmlFree(propstr);
- return rval ;
+ return rvalue ;
}
/*
@@ -1288,7 +1303,7 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
child_iter = node;
while (child_iter->parent)
child_iter = child_iter->parent;
-
+
if (child_iter->type == XML_DOCUMENT_FRAG_NODE)
node->doc->children = NULL;
}

0 comments on commit 765d8dd

Please sign in to comment.