diff --git a/ext/java/nokogiri/XmlSchema.java b/ext/java/nokogiri/XmlSchema.java index ea3e55eff0..d965965976 100644 --- a/ext/java/nokogiri/XmlSchema.java +++ b/ext/java/nokogiri/XmlSchema.java @@ -143,18 +143,18 @@ public class XmlSchema extends RubyObject public static IRubyObject from_document(ThreadContext context, IRubyObject klazz, IRubyObject[] args) { - IRubyObject document = args[0]; + IRubyObject rbDocument = args[0]; IRubyObject parseOptions = null; if (args.length > 1) { parseOptions = args[1]; } - if (!(document instanceof XmlDocument)) { + if (!(rbDocument instanceof XmlDocument)) { // TODO: deprecate allowing Node context.runtime.getWarnings().warn("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri."); } - XmlDocument doc = ((XmlDocument)((XmlNode) document).document(context)); + XmlDocument doc = ((XmlDocument)((XmlNode) rbDocument).document(context)); RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors"); if (!errors.isEmpty()) { diff --git a/ext/nokogiri/xml_schema.c b/ext/nokogiri/xml_schema.c index 5aeecb1e6f..c08eb11d79 100644 --- a/ext/nokogiri/xml_schema.c +++ b/ext/nokogiri/xml_schema.c @@ -203,7 +203,7 @@ read_memory(int argc, VALUE *argv, VALUE klass) * [Returns] Nokogiri::XML::Schema */ static VALUE -from_document(int argc, VALUE *argv, VALUE klass) +rb_xml_schema_s_from_document(int argc, VALUE *argv, VALUE klass) { VALUE rb_document; VALUE rb_parse_options; @@ -214,14 +214,14 @@ from_document(int argc, VALUE *argv, VALUE klass) rb_scan_args(argc, argv, "11", &rb_document, &rb_parse_options); - if (rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) { - c_document = noko_xml_document_unwrap(rb_document); - } else { + if (!rb_obj_is_kind_of(rb_document, cNokogiriXmlDocument)) { xmlNodePtr deprecated_node_type_arg; // TODO: deprecate allowing Node NOKO_WARN_DEPRECATION("Passing a Node as the first parameter to Schema.from_document is deprecated. Please pass a Document instead. This will become an error in a future release of Nokogiri."); Noko_Node_Get_Struct(rb_document, xmlNode, deprecated_node_type_arg); c_document = deprecated_node_type_arg->doc; + } else { + c_document = noko_xml_document_unwrap(rb_document); } if (noko_xml_document_has_wrapped_blank_nodes_p(c_document)) { @@ -249,7 +249,7 @@ noko_init_xml_schema(void) rb_undef_alloc_func(cNokogiriXmlSchema); rb_define_singleton_method(cNokogiriXmlSchema, "read_memory", read_memory, -1); - rb_define_singleton_method(cNokogiriXmlSchema, "from_document", from_document, -1); + rb_define_singleton_method(cNokogiriXmlSchema, "from_document", rb_xml_schema_s_from_document, -1); rb_define_private_method(cNokogiriXmlSchema, "validate_document", validate_document, 1); rb_define_private_method(cNokogiriXmlSchema, "validate_file", validate_file, 1);