Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: adhearsion/nokogiri
...
head fork: adhearsion/nokogiri
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 38 additions and 0 deletions.
  1. +26 −0 ext/nokogiri/xml_reader.c
  2. +12 −0 test/test_reader.rb
View
26 ext/nokogiri/xml_reader.c
@@ -622,6 +622,31 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
/*
* call-seq:
+ * reader.expand # => #<Nokogiri::XML::Node>
+ *
+ * Returns an expanded subtree of the reader
+ */
+static VALUE expand(VALUE self)
+{
+ xmlTextReaderPtr reader;
+ xmlNodePtr node;
+
+ Data_Get_Struct(self, xmlTextReader, reader);
+
+ node = xmlTextReaderExpand(reader);
+
+ assert(node->doc);
+
+ if(!node->doc->_private)
+ Nokogiri_wrap_xml_document(cNokogiriXmlDocument, node->doc);
+
+ if(node) return Nokogiri_wrap_xml_node(Qnil, node);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
* reader.empty_element? # => true or false
*
* Returns true if the current node is empty, otherwise false.
@@ -668,6 +693,7 @@ void init_xml_reader()
rb_define_method(klass, "prefix", prefix, 0);
rb_define_method(klass, "value", value, 0);
rb_define_method(klass, "lang", lang, 0);
+ rb_define_method(klass, "expand", expand, 0);
rb_define_method(klass, "xml_version", xml_version, 0);
rb_define_method(klass, "depth", depth, 0);
rb_define_method(klass, "attribute_count", attribute_count, 0);
View
12 test/test_reader.rb
@@ -2,6 +2,18 @@
require "helper"
class TestReader < Nokogiri::TestCase
+ def test_expand
+ io = File.open XML_FILE
+ reader = Nokogiri::XML::Reader.from_io(io)
+ names = []
+ reader.each do |cursor|
+ if 'employee' == cursor.name
+ node = cursor.expand
+ assert_instance_of(Nokogiri::XML::Element, node)
+ end
+ end
+ end
+
def test_from_io_sets_io_as_source
io = File.open SNUGGLES_FILE
reader = Nokogiri::XML::Reader.from_io(io)

No commit comments for this range

Something went wrong with that request. Please try again.