Commit 80f134f0 authored by Aaron Patterson's avatar Aaron Patterson

adding an internal subset event

parent e5eccd5d
......@@ -253,6 +253,26 @@ static void attribute_declaration(void * ctx,
);
}
static void internal_subset(void * ctx,
const xmlChar *name,
const xmlChar *externalId,
const xmlChar *systemId)
{
VALUE self = (VALUE)ctx;
VALUE MAYBE_UNUSED(enc) = rb_iv_get(self, "@encoding");
VALUE doc = rb_funcall(self, rb_intern("document"), 0);
char * MAYBE_UNUSED(encoding) = RTEST(enc) ? StringValuePtr(enc) : NULL;
rb_funcall(doc,
rb_intern("internal_subset"),
3,
NOKOGIRI_STR_NEW2(name, encoding),
externalId == NULL ? Qnil : NOKOGIRI_STR_NEW2(externalId, encoding),
systemId == NULL ? Qnil : NOKOGIRI_STR_NEW2(systemId, encoding)
);
}
static void deallocate(xmlSAXHandlerPtr handler)
{
NOKOGIRI_DEBUG_START(handler);
......@@ -276,6 +296,7 @@ static VALUE allocate(VALUE klass)
handler->warning = warning_func;
handler->error = error_func;
handler->cdataBlock = cdata_block;
handler->internalSubset = internal_subset;
return Data_Wrap_Struct(klass, NULL, deallocate, handler);
}
......
......@@ -148,6 +148,14 @@ module Nokogiri
# +value_set+ is a list of possible values (may be empty)
def attribute_declaration element_name, attribute_name, type, default_type, default_value, value_set
end
###
# Called when parsing an internal subset declaration
# +name+ is the root element name
# +external_id+ is the external id
# +system_id+ is the system id, filename or URL
def internal_subset name, external_id, system_id
end
end
end
end
......
......@@ -58,7 +58,7 @@ module Nokogiri
attr_reader :end_elements, :end_document_called
attr_reader :data, :comments, :cdata_blocks, :entity_declarations
attr_reader :errors, :warnings, :notation_declarations
attr_reader :attribute_declarations
attr_reader :attribute_declarations, :internal_subsets
def initialize
@start_document_called = nil
......@@ -73,6 +73,7 @@ module Nokogiri
@entity_declarations = []
@notation_declarations = []
@attribute_declarations = []
@internal_subsets = []
end
def start_document
......@@ -134,6 +135,11 @@ module Nokogiri
@attribute_declarations << args
super
end
def internal_subset name, external_id, system_id
@internal_subsets << [name, external_id, system_id]
super
end
end
end
end
......
......@@ -9,6 +9,12 @@ module Nokogiri
@parser = XML::SAX::Parser.new(Doc.new)
end
def test_internal_subset
File.open(XML_FILE, 'rb') { |f| @parser.parse(f) }
assert_equal ['staff', nil, 'staff.dtd'],
@parser.document.internal_subsets.first
end
def test_entity_declaration
File.open(XML_FILE, 'rb') { |f|
@parser.parse(f)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment