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
local implementation of xmlTextReaderHasAttributes for common versions of 
libxml2 that don't look at namespaces.
mdalessio (author)
Thu Sep 25 16:14:00 -0700 2008
commit  c92dba401ebfd061863c62f1225fdb08374f16fa
tree    617178d9a6fe4ed6ffaf73d00653d48a3da930d7
parent  c5e7c3771b2bee6393360988fbfdc88ae440ec64
...
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
...
49
50
51
52
 
53
54
55
...
71
72
73
74
 
75
76
77
...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
67
68
69
 
70
71
72
73
...
89
90
91
 
92
93
94
95
0
@@ -5,6 +5,24 @@ static void dealloc(xmlTextReaderPtr reader)
0
   xmlFreeTextReader(reader);
0
 }
0
 
0
+static int has_attributes(xmlTextReaderPtr reader)
0
+{
0
+ /*
0
+ * this implementation of xmlTextReaderHasAttributes explicitly includes
0
+ * namespaces and properties, because some earlier versions ignore
0
+ * namespaces.
0
+ */
0
+ xmlNodePtr node ;
0
+ node = xmlTextReaderCurrentNode(reader);
0
+ if (node == NULL)
0
+ return(0);
0
+
0
+ if ((node->type == XML_ELEMENT_NODE) &&
0
+ ((node->properties != NULL) || (node->nsDef != NULL)))
0
+ return(1);
0
+ return(0);
0
+}
0
+
0
 /*
0
  * call-seq:
0
  * default?
0
@@ -49,7 +67,7 @@ static VALUE attributes_eh(VALUE self)
0
 {
0
   xmlTextReaderPtr reader;
0
   Data_Get_Struct(self, xmlTextReader, reader);
0
- int eh = xmlTextReaderHasAttributes(reader);
0
+ int eh = has_attributes(reader);
0
   if(eh == 0) return Qfalse;
0
   if(eh == 1) return Qtrue;
0
 
0
@@ -71,7 +89,7 @@ static VALUE attributes(VALUE self)
0
 
0
   attr = rb_hash_new() ;
0
 
0
- if (! xmlTextReaderHasAttributes(reader))
0
+ if (! has_attributes(reader))
0
     return attr ;
0
 
0
   xmlNodePtr ptr = xmlTextReaderExpand(reader);

Comments

    No one has commented yet.