Skip to content

Commit

Permalink
adding xml document fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 16, 2009
1 parent 260363f commit a325202
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ ext/nokogiri/xml_comment.c
ext/nokogiri/xml_comment.h
ext/nokogiri/xml_document.c
ext/nokogiri/xml_document.h
ext/nokogiri/xml_document_fragment.c
ext/nokogiri/xml_document_fragment.h
ext/nokogiri/xml_dtd.c
ext/nokogiri/xml_dtd.h
ext/nokogiri/xml_io.c
Expand Down Expand Up @@ -133,6 +135,7 @@ test/xml/test_builder.rb
test/xml/test_cdata.rb
test/xml/test_comment.rb
test/xml/test_document.rb
test/xml/test_document_fragment.rb
test/xml/test_dtd.rb
test/xml/test_node.rb
test/xml/test_node_set.rb
Expand Down
1 change: 1 addition & 0 deletions ext/nokogiri/native.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void Init_native()
init_xml_document();
init_html_document();
init_xml_node();
init_xml_document_fragment();
init_xml_text();
init_xml_cdata();
init_xml_comment();
Expand Down
1 change: 1 addition & 0 deletions ext/nokogiri/native.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <xml_node.h>
#include <xml_text.h>
#include <xml_cdata.h>
#include <xml_document_fragment.h>
#include <xml_comment.h>
#include <xml_node_set.h>
#include <xml_xpath.h>
Expand Down
38 changes: 38 additions & 0 deletions ext/nokogiri/xml_document_fragment.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <xml_document_fragment.h>

/*
* call-seq:
* new(document)
*
* Create a new DocumentFragment element on the +document+
*/
static VALUE new(VALUE klass, VALUE doc)
{
xmlDocPtr xml_doc;
Data_Get_Struct(doc, xmlDoc, xml_doc);

xmlNodePtr node = xmlNewDocFragment(xml_doc);

VALUE rb_node = Nokogiri_wrap_xml_node(node);

if(rb_block_given_p()) rb_yield(rb_node);

return rb_node;
}

VALUE cNokogiriXmlDocumentFragment;
void init_xml_document_fragment()
{
VALUE nokogiri = rb_define_module("Nokogiri");
VALUE xml = rb_define_module_under(nokogiri, "XML");
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);

/*
* DocumentFragment represents a DocumentFragment node in an xml document.
*/
VALUE klass = rb_define_class_under(xml, "DocumentFragment", node);

cNokogiriXmlDocumentFragment = klass;

rb_define_singleton_method(klass, "new", new, 1);
}
10 changes: 10 additions & 0 deletions ext/nokogiri/xml_document_fragment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef NOKOGIRI_XML_DOCUMENT_FRAGMENT
#define NOKOGIRI_XML_DOCUMENT_FRAGMENT

#include <native.h>

void init_xml_document_fragment();

extern VALUE cNokogiriXmlDocumentFragment;
#endif

12 changes: 12 additions & 0 deletions test/xml/test_document_fragment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))

module Nokogiri
module XML
class TestDocumentFragment < Nokogiri::TestCase
def test_new
@xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
fragment = Nokogiri::XML::DocumentFragment.new(@xml)
end
end
end
end

0 comments on commit a325202

Please sign in to comment.