public
Description: Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support.
Homepage: http://nokogiri.rubyforge.org/
Clone URL: git://github.com/tenderlove/nokogiri.git
working around namespaces in older version of libxml2.
mdalessio (author)
Thu Sep 25 17:06:25 -0700 2008
commit  b73f00984d4ad401a198c931c4e3287bd888e724
tree    ffeb6027e0f187f127a58c268b8e85cb08c7dcfa
parent  c92dba401ebfd061863c62f1225fdb08374f16fa
...
135
136
137
 
138
139
140
141
142
143
144
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
147
148
...
135
136
137
138
139
140
141
 
 
 
 
 
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
0
@@ -135,14 +135,25 @@ static VALUE attribute_at(VALUE self, VALUE index)
0
 static VALUE reader_attribute(VALUE self, VALUE name)
0
 {
0
   xmlTextReaderPtr reader;
0
+ xmlChar *value ;
0
   Data_Get_Struct(self, xmlTextReader, reader);
0
 
0
   if(name == Qnil) return Qnil;
0
-
0
- xmlChar * value = xmlTextReaderGetAttribute(
0
- reader,
0
- (const xmlChar *)StringValuePtr(name)
0
- );
0
+ name = StringValue(name) ;
0
+
0
+ value = xmlTextReaderGetAttribute(reader, (xmlChar*)RSTRING(name)->ptr );
0
+ if(value == NULL) {
0
+ /* this section is an attempt to workaround older versions of libxml that
0
+ don't handle namespaces properly in all attribute-and-friends functions */
0
+ xmlChar *prefix = NULL ;
0
+ xmlChar *localname = xmlSplitQName2((xmlChar*)RSTRING(name)->ptr, &prefix);
0
+ if (localname != NULL) {
0
+ value = xmlTextReaderLookupNamespace(reader, localname);
0
+ free(localname) ;
0
+ } else {
0
+ value = xmlTextReaderLookupNamespace(reader, prefix);
0
+ }
0
+ }
0
   if(value == NULL) return Qnil;
0
 
0
   VALUE rb_value = rb_str_new2((const char *)value);

Comments

    No one has commented yet.