Skip to content
This repository
Browse code

basic expand feature. totally borked

  • Loading branch information...
commit 54d784a84f5005782f33a60295b1c677fbae81dc 1 parent 5c18023
Aaron Patterson authored June 23, 2010
26  ext/nokogiri/xml_reader.c
@@ -622,6 +622,31 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
622 622
 
623 623
 /*
624 624
  * call-seq:
  625
+ *   reader.expand # => #<Nokogiri::XML::Node>
  626
+ *
  627
+ * Returns an expanded subtree of the reader
  628
+ */
  629
+static VALUE expand(VALUE self)
  630
+{
  631
+  xmlTextReaderPtr reader;
  632
+  xmlNodePtr node;
  633
+
  634
+  Data_Get_Struct(self, xmlTextReader, reader);
  635
+
  636
+  node = xmlTextReaderExpand(reader);
  637
+
  638
+  assert(node->doc);
  639
+
  640
+  if(!node->doc->_private)
  641
+    Nokogiri_wrap_xml_document(cNokogiriXmlDocument, node->doc);
  642
+
  643
+  if(node) return Nokogiri_wrap_xml_node(Qnil, node);
  644
+
  645
+  return Qnil;
  646
+}
  647
+
  648
+/*
  649
+ * call-seq:
625 650
  *   reader.empty_element? # => true or false
626 651
  *
627 652
  * Returns true if the current node is empty, otherwise false.
@@ -668,6 +693,7 @@ void init_xml_reader()
668 693
   rb_define_method(klass, "prefix", prefix, 0);
669 694
   rb_define_method(klass, "value", value, 0);
670 695
   rb_define_method(klass, "lang", lang, 0);
  696
+  rb_define_method(klass, "expand", expand, 0);
671 697
   rb_define_method(klass, "xml_version", xml_version, 0);
672 698
   rb_define_method(klass, "depth", depth, 0);
673 699
   rb_define_method(klass, "attribute_count", attribute_count, 0);
12  test/test_reader.rb
@@ -2,6 +2,18 @@
2 2
 require "helper"
3 3
 
4 4
 class TestReader < Nokogiri::TestCase
  5
+  def test_expand
  6
+    io = File.open XML_FILE
  7
+    reader = Nokogiri::XML::Reader.from_io(io)
  8
+    names = []
  9
+    reader.each do |cursor|
  10
+      if 'employee' == cursor.name
  11
+        node = cursor.expand
  12
+        assert_instance_of(Nokogiri::XML::Element, node)
  13
+      end
  14
+    end
  15
+  end
  16
+
5 17
   def test_from_io_sets_io_as_source
6 18
     io = File.open SNUGGLES_FILE
7 19
     reader = Nokogiri::XML::Reader.from_io(io)

0 notes on commit 54d784a

Please sign in to comment.
Something went wrong with that request. Please try again.