libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGES +28 -0
  2. data/README +8 -12
  3. data/ext/libxml/cbg.c +86 -86
  4. data/ext/libxml/libxml.c +875 -899
  5. data/ext/libxml/ruby_libxml.h +91 -65
  6. data/ext/libxml/ruby_xml_attr.c +485 -485
  7. data/ext/libxml/ruby_xml_attr.h +3 -3
  8. data/ext/libxml/ruby_xml_attributes.h +2 -2
  9. data/ext/libxml/ruby_xml_document.c +124 -307
  10. data/ext/libxml/ruby_xml_document.h +3 -3
  11. data/ext/libxml/ruby_xml_dtd.c +119 -119
  12. data/ext/libxml/ruby_xml_dtd.h +2 -2
  13. data/ext/libxml/ruby_xml_error.c +1 -1
  14. data/ext/libxml/ruby_xml_error.h +2 -2
  15. data/ext/libxml/ruby_xml_html_parser.c +119 -119
  16. data/ext/libxml/ruby_xml_html_parser.h +3 -3
  17. data/ext/libxml/ruby_xml_input.c +13 -11
  18. data/ext/libxml/ruby_xml_input.h +3 -3
  19. data/ext/libxml/ruby_xml_input_cbg.c +197 -197
  20. data/ext/libxml/ruby_xml_namespace.c +158 -0
  21. data/ext/libxml/ruby_xml_namespace.h +12 -0
  22. data/ext/libxml/ruby_xml_namespaces.c +303 -0
  23. data/ext/libxml/{ruby_xml_ns.h → ruby_xml_namespaces.h} +4 -5
  24. data/ext/libxml/ruby_xml_node.c +88 -293
  25. data/ext/libxml/ruby_xml_node.h +4 -4
  26. data/ext/libxml/ruby_xml_parser.c +152 -152
  27. data/ext/libxml/ruby_xml_parser.h +3 -3
  28. data/ext/libxml/ruby_xml_parser_context.c +630 -657
  29. data/ext/libxml/ruby_xml_parser_context.h +3 -3
  30. data/ext/libxml/ruby_xml_reader.c +899 -904
  31. data/ext/libxml/ruby_xml_reader.h +2 -2
  32. data/ext/libxml/ruby_xml_relaxng.h +2 -2
  33. data/ext/libxml/ruby_xml_sax_parser.c +175 -175
  34. data/ext/libxml/ruby_xml_sax_parser.h +3 -3
  35. data/ext/libxml/ruby_xml_schema.c +165 -165
  36. data/ext/libxml/ruby_xml_schema.h +2 -2
  37. data/ext/libxml/ruby_xml_state.h +2 -2
  38. data/ext/libxml/ruby_xml_xinclude.c +24 -24
  39. data/ext/libxml/ruby_xml_xinclude.h +3 -3
  40. data/ext/libxml/ruby_xml_xpath.c +108 -108
  41. data/ext/libxml/ruby_xml_xpath.h +3 -3
  42. data/ext/libxml/ruby_xml_xpath_context.c +84 -35
  43. data/ext/libxml/ruby_xml_xpath_context.h +3 -3
  44. data/ext/libxml/ruby_xml_xpath_expression.c +5 -7
  45. data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
  46. data/ext/libxml/ruby_xml_xpath_object.c +7 -7
  47. data/ext/libxml/ruby_xml_xpath_object.h +2 -2
  48. data/ext/libxml/ruby_xml_xpointer.c +107 -107
  49. data/ext/libxml/ruby_xml_xpointer.h +3 -3
  50. data/ext/libxml/version.h +2 -2
  51. data/ext/mingw/libxml_ruby.dll.a +0 -0
  52. data/ext/mingw/libxml_ruby.so +0 -0
  53. data/ext/vc/libxml_ruby.vcproj +13 -5
  54. data/lib/libxml.rb +4 -1
  55. data/lib/libxml/document.rb +40 -6
  56. data/lib/libxml/hpricot.rb +76 -76
  57. data/lib/libxml/namespace.rb +60 -0
  58. data/lib/libxml/namespaces.rb +36 -0
  59. data/lib/libxml/node.rb +90 -26
  60. data/lib/libxml/ns.rb +20 -0
  61. data/test/model/bands.xml +5 -0
  62. data/test/tc_attributes.rb +1 -1
  63. data/test/tc_document.rb +24 -41
  64. data/test/tc_document_write.rb +87 -115
  65. data/test/tc_namespace.rb +59 -0
  66. data/test/tc_namespaces.rb +174 -0
  67. data/test/tc_node.rb +41 -33
  68. data/test/tc_node_copy.rb +1 -1
  69. data/test/tc_node_edit.rb +6 -0
  70. data/test/tc_node_write.rb +76 -0
  71. data/test/tc_xinclude.rb +2 -9
  72. data/test/tc_xpath.rb +38 -11
  73. data/test/test_suite.rb +3 -1
  74. metadata +16 -9
  75. data/ext/libxml/ruby_xml_ns.c +0 -150
  76. data/test/ets_copy_bug.rb +0 -21
  77. data/test/ets_copy_bug3.rb +0 -38
  78. data/test/model/default_validation_bug.rb +0 -0
  79. data/test/tc_ns.rb +0 -18
@@ -1,8 +1,8 @@
1
1
  /* Copyright (c) 2006 Apple Computer Inc.
2
2
  * Please see the LICENSE file for copyright and distribution information. */
3
3
 
4
- #ifndef __rxml_READER__
5
- #define __rxml_READER__
4
+ #ifndef __RXML_READER__
5
+ #define __RXML_READER__
6
6
 
7
7
  extern VALUE cXMLReader;
8
8
 
@@ -1,5 +1,5 @@
1
- #ifndef __rxml_RELAXNG__
2
- #define __rxml_RELAXNG__
1
+ #ifndef __RXML_RELAXNG__
2
+ #define __RXML_RELAXNG__
3
3
 
4
4
  #include <libxml/relaxng.h>
5
5
 
@@ -1,175 +1,175 @@
1
- /* $Id: ruby_xml_sax_parser.c 650 2008-11-30 03:40:22Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_sax_parser.h"
7
-
8
- /*
9
- * Document-class: LibXML::XML::SaxParser
10
- *
11
- * XML::SaxParser provides a callback based API for parsing documents,
12
- * in contrast to XML::Parser's tree based API and XML::Reader's stream
13
- * based API.
14
- *
15
- * Note that the XML::SaxParser API is fairly complex, not well standardized,
16
- * and does not directly support validation making entity, namespace and
17
- * base processing relatively hard.
18
- *
19
- * To use the XML::SaxParser, register a callback class via the
20
- * XML::SaxParser#callbacks=. It is easiest to include the
21
- * XML::SaxParser::Callbacks module in your class and override
22
- * the methods as needed.
23
- *
24
- * Basic example:
25
- *
26
- * class MyCallbacks
27
- * include XML::SaxParser::Callbacks
28
- * def on_start_element(element, attributes)
29
- * puts #Element started: #{element}"
30
- * end
31
- * end
32
- *
33
- * parser = XML::SaxParser.new
34
- * parser.callbacks = MyCallbacks.new
35
- * parser.parse
36
- */
37
-
38
- VALUE cXMLSaxParser;
39
- VALUE mXMLSaxParserCallbacks;
40
-
41
- static ID INPUT_ATTR;
42
- static ID CALLBACKS_ATTR;
43
-
44
- VALUE cbidOnInternalSubset;
45
- VALUE cbidOnIsStandalone;
46
- VALUE cbidOnHasInternalSubset;
47
- VALUE cbidOnHasExternalSubset;
48
- VALUE cbidOnStartDocument;
49
- VALUE cbidOnEndDocument;
50
- VALUE cbidOnStartElement;
51
- VALUE cbidOnEndElement;
52
- VALUE cbidOnReference;
53
- VALUE cbidOnCharacters;
54
- VALUE cbidOnProcessingInstruction;
55
- VALUE cbidOnComment;
56
- VALUE cbidOnXmlParserWarning;
57
- VALUE cbidOnXmlParserError;
58
- VALUE cbidOnXmlParserFatalError;
59
- VALUE cbidOnCdataBlock;
60
- VALUE cbidOnExternalSubset;
61
-
62
- #include "sax_parser_callbacks.inc"
63
-
64
- /*
65
- * call-seq:
66
- * sax_parser.initialize -> sax_parser
67
- *
68
- * Initiliazes instance of parser.
69
- */
70
- static VALUE rxml_sax_parser_initialize(VALUE self)
71
- {
72
- VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
73
- rb_iv_set(self, "@input", input);
74
- return self;
75
- }
76
-
77
- /* Parsing data sources */
78
- static int rxml_sax_parser_parse_file(VALUE self, VALUE input)
79
- {
80
- VALUE file = rb_ivar_get(input, FILE_ATTR);
81
- return xmlSAXUserParseFile((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
82
- (void *) self, StringValuePtr(file));
83
- }
84
-
85
- static int rxml_sax_parser_parse_string(VALUE self, VALUE input)
86
- {
87
- VALUE str = rb_ivar_get(input, STRING_ATTR);
88
- return xmlSAXUserParseMemory((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
89
- (void *) self, StringValuePtr(str), RSTRING_LEN(str));
90
- }
91
-
92
- static int rxml_sax_parser_parse_io(VALUE self, VALUE input)
93
- {
94
- VALUE io = rb_ivar_get(input, IO_ATTR);
95
- VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
96
- xmlCharEncoding xmlEncoding = NUM2INT(encoding);
97
- xmlParserCtxtPtr ctxt =
98
- xmlCreateIOParserCtxt((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
99
- (void *) self, (xmlInputReadCallback) rxml_read_callback, NULL,
100
- (void *) io, xmlEncoding);
101
- return xmlParseDocument(ctxt);
102
- }
103
-
104
- /*
105
- * call-seq:
106
- * parser.parse -> (true|false)
107
- *
108
- * Parse the input XML, generating callbacks to the object
109
- * registered via the +callbacks+ attributesibute.
110
- */
111
- static VALUE rxml_sax_parser_parse(VALUE self)
112
- {
113
- int status;
114
- VALUE input = rb_ivar_get(self, INPUT_ATTR);
115
-
116
- if (rb_ivar_get(input, FILE_ATTR) != Qnil)
117
- status = rxml_sax_parser_parse_file(self, input);
118
- else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
119
- status = rxml_sax_parser_parse_string(self, input);
120
- else if (rb_ivar_get(input, IO_ATTR) != Qnil)
121
- status = rxml_sax_parser_parse_io(self, input);
122
- else
123
- rb_raise(rb_eArgError, "You must specify a parser data source");
124
-
125
- if (status)
126
- {
127
- rxml_raise(&xmlLastError);
128
- return Qfalse;
129
- }
130
- else
131
- {
132
- return (Qtrue);
133
- }
134
- }
135
-
136
- // Rdoc needs to know
137
- #ifdef RDOC_NEVER_DEFINED
138
- mLibXML = rb_define_module("LibXML");
139
- mXML = rb_define_module_under(mLibXML, "XML");
140
- #endif
141
-
142
- void ruby_init_xml_sax_parser(void)
143
- {
144
- /* SaxParser */
145
- cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
146
-
147
- /* Atributes */
148
- CALLBACKS_ATTR = rb_intern("@callbacks");
149
- INPUT_ATTR = rb_intern("@input");
150
- rb_define_attr(cXMLSaxParser, "callbacks", 1, 1);
151
- rb_define_attr(cXMLSaxParser, "input", 1, 0);
152
-
153
- /* Instance Methods */
154
- rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, 0);
155
- rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0);
156
-
157
- /* SaxCallbacks */
158
- cbidOnInternalSubset = rb_intern("on_internal_subset");
159
- cbidOnIsStandalone = rb_intern("on_is_standalone");
160
- cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
161
- cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
162
- cbidOnStartDocument = rb_intern("on_start_document");
163
- cbidOnEndDocument = rb_intern("on_end_document");
164
- cbidOnStartElement = rb_intern("on_start_element");
165
- cbidOnEndElement = rb_intern("on_end_element");
166
- cbidOnReference = rb_intern("on_reference");
167
- cbidOnCharacters = rb_intern("on_characters");
168
- cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
169
- cbidOnComment = rb_intern("on_comment");
170
- cbidOnXmlParserWarning = rb_intern("on_parser_warning");
171
- cbidOnXmlParserError = rb_intern("on_parser_error");
172
- cbidOnXmlParserFatalError = rb_intern("on_parser_fatal_error");
173
- cbidOnCdataBlock = rb_intern("on_cdata_block");
174
- cbidOnExternalSubset = rb_intern("on_external_subset");
175
- }
1
+ /* $Id: ruby_xml_sax_parser.c 650 2008-11-30 03:40:22Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_sax_parser.h"
7
+
8
+ /*
9
+ * Document-class: LibXML::XML::SaxParser
10
+ *
11
+ * XML::SaxParser provides a callback based API for parsing documents,
12
+ * in contrast to XML::Parser's tree based API and XML::Reader's stream
13
+ * based API.
14
+ *
15
+ * Note that the XML::SaxParser API is fairly complex, not well standardized,
16
+ * and does not directly support validation making entity, namespace and
17
+ * base processing relatively hard.
18
+ *
19
+ * To use the XML::SaxParser, register a callback class via the
20
+ * XML::SaxParser#callbacks=. It is easiest to include the
21
+ * XML::SaxParser::Callbacks module in your class and override
22
+ * the methods as needed.
23
+ *
24
+ * Basic example:
25
+ *
26
+ * class MyCallbacks
27
+ * include XML::SaxParser::Callbacks
28
+ * def on_start_element(element, attributes)
29
+ * puts #Element started: #{element}"
30
+ * end
31
+ * end
32
+ *
33
+ * parser = XML::SaxParser.new
34
+ * parser.callbacks = MyCallbacks.new
35
+ * parser.parse
36
+ */
37
+
38
+ VALUE cXMLSaxParser;
39
+ VALUE mXMLSaxParserCallbacks;
40
+
41
+ static ID INPUT_ATTR;
42
+ static ID CALLBACKS_ATTR;
43
+
44
+ VALUE cbidOnInternalSubset;
45
+ VALUE cbidOnIsStandalone;
46
+ VALUE cbidOnHasInternalSubset;
47
+ VALUE cbidOnHasExternalSubset;
48
+ VALUE cbidOnStartDocument;
49
+ VALUE cbidOnEndDocument;
50
+ VALUE cbidOnStartElement;
51
+ VALUE cbidOnEndElement;
52
+ VALUE cbidOnReference;
53
+ VALUE cbidOnCharacters;
54
+ VALUE cbidOnProcessingInstruction;
55
+ VALUE cbidOnComment;
56
+ VALUE cbidOnXmlParserWarning;
57
+ VALUE cbidOnXmlParserError;
58
+ VALUE cbidOnXmlParserFatalError;
59
+ VALUE cbidOnCdataBlock;
60
+ VALUE cbidOnExternalSubset;
61
+
62
+ #include "sax_parser_callbacks.inc"
63
+
64
+ /*
65
+ * call-seq:
66
+ * sax_parser.initialize -> sax_parser
67
+ *
68
+ * Initiliazes instance of parser.
69
+ */
70
+ static VALUE rxml_sax_parser_initialize(VALUE self)
71
+ {
72
+ VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
73
+ rb_iv_set(self, "@input", input);
74
+ return self;
75
+ }
76
+
77
+ /* Parsing data sources */
78
+ static int rxml_sax_parser_parse_file(VALUE self, VALUE input)
79
+ {
80
+ VALUE file = rb_ivar_get(input, FILE_ATTR);
81
+ return xmlSAXUserParseFile((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
82
+ (void *) self, StringValuePtr(file));
83
+ }
84
+
85
+ static int rxml_sax_parser_parse_string(VALUE self, VALUE input)
86
+ {
87
+ VALUE str = rb_ivar_get(input, STRING_ATTR);
88
+ return xmlSAXUserParseMemory((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
89
+ (void *) self, StringValuePtr(str), RSTRING_LEN(str));
90
+ }
91
+
92
+ static int rxml_sax_parser_parse_io(VALUE self, VALUE input)
93
+ {
94
+ VALUE io = rb_ivar_get(input, IO_ATTR);
95
+ VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
96
+ xmlCharEncoding xmlEncoding = NUM2INT(encoding);
97
+ xmlParserCtxtPtr ctxt =
98
+ xmlCreateIOParserCtxt((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
99
+ (void *) self, (xmlInputReadCallback) rxml_read_callback, NULL,
100
+ (void *) io, xmlEncoding);
101
+ return xmlParseDocument(ctxt);
102
+ }
103
+
104
+ /*
105
+ * call-seq:
106
+ * parser.parse -> (true|false)
107
+ *
108
+ * Parse the input XML, generating callbacks to the object
109
+ * registered via the +callbacks+ attributesibute.
110
+ */
111
+ static VALUE rxml_sax_parser_parse(VALUE self)
112
+ {
113
+ int status;
114
+ VALUE input = rb_ivar_get(self, INPUT_ATTR);
115
+
116
+ if (rb_ivar_get(input, FILE_ATTR) != Qnil)
117
+ status = rxml_sax_parser_parse_file(self, input);
118
+ else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
119
+ status = rxml_sax_parser_parse_string(self, input);
120
+ else if (rb_ivar_get(input, IO_ATTR) != Qnil)
121
+ status = rxml_sax_parser_parse_io(self, input);
122
+ else
123
+ rb_raise(rb_eArgError, "You must specify a parser data source");
124
+
125
+ if (status)
126
+ {
127
+ rxml_raise(&xmlLastError);
128
+ return Qfalse;
129
+ }
130
+ else
131
+ {
132
+ return (Qtrue);
133
+ }
134
+ }
135
+
136
+ // Rdoc needs to know
137
+ #ifdef RDOC_NEVER_DEFINED
138
+ mLibXML = rb_define_module("LibXML");
139
+ mXML = rb_define_module_under(mLibXML, "XML");
140
+ #endif
141
+
142
+ void ruby_init_xml_sax_parser(void)
143
+ {
144
+ /* SaxParser */
145
+ cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
146
+
147
+ /* Atributes */
148
+ CALLBACKS_ATTR = rb_intern("@callbacks");
149
+ INPUT_ATTR = rb_intern("@input");
150
+ rb_define_attr(cXMLSaxParser, "callbacks", 1, 1);
151
+ rb_define_attr(cXMLSaxParser, "input", 1, 0);
152
+
153
+ /* Instance Methods */
154
+ rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, 0);
155
+ rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0);
156
+
157
+ /* SaxCallbacks */
158
+ cbidOnInternalSubset = rb_intern("on_internal_subset");
159
+ cbidOnIsStandalone = rb_intern("on_is_standalone");
160
+ cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
161
+ cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
162
+ cbidOnStartDocument = rb_intern("on_start_document");
163
+ cbidOnEndDocument = rb_intern("on_end_document");
164
+ cbidOnStartElement = rb_intern("on_start_element");
165
+ cbidOnEndElement = rb_intern("on_end_element");
166
+ cbidOnReference = rb_intern("on_reference");
167
+ cbidOnCharacters = rb_intern("on_characters");
168
+ cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
169
+ cbidOnComment = rb_intern("on_comment");
170
+ cbidOnXmlParserWarning = rb_intern("on_parser_warning");
171
+ cbidOnXmlParserError = rb_intern("on_parser_error");
172
+ cbidOnXmlParserFatalError = rb_intern("on_parser_fatal_error");
173
+ cbidOnCdataBlock = rb_intern("on_cdata_block");
174
+ cbidOnExternalSubset = rb_intern("on_external_subset");
175
+ }
@@ -1,9 +1,9 @@
1
- /* $Id: ruby_xml_sax_parser.h 616 2008-11-22 09:25:12Z cfis $ */
1
+ /* $Id: ruby_xml_sax_parser.h 666 2008-12-07 00:16:50Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
- #ifndef __rxml_SAX_PARSER__
6
- #define __rxml_SAX_PARSER__
5
+ #ifndef __RXML_SAX_PARSER__
6
+ #define __RXML_SAX_PARSER__
7
7
 
8
8
  extern VALUE cXMLSaxParser;
9
9
 
@@ -1,165 +1,165 @@
1
- #include "ruby_libxml.h"
2
- #include "ruby_xml_schema.h"
3
-
4
- /*
5
- * Document-class: LibXML::XML::Schema
6
- *
7
- * The XML::Schema class is used to prepare XML Schemas for validation of xml
8
- * documents.
9
- *
10
- * Schemas can be created from XML documents, strings or URIs using the
11
- * corresponding methods (new for URIs).
12
- *
13
- * Once a schema is prepared, an XML document can be validated by the
14
- * XML::Document#validate_schema method providing the XML::Schema object
15
- * as parameter. The method return true if the document validates, false
16
- * otherwise.
17
- *
18
- * Basic usage:
19
- *
20
- * # parse schema as xml document
21
- * schema_document = XML::Document.file('schema.rng')
22
- *
23
- * # prepare schema for validation
24
- * schema = XML::Schema.document(schema_document)
25
- *
26
- * # parse xml document to be validated
27
- * instance = XML::Document.file('instance.xml')
28
- *
29
- * # validate
30
- * instance.validate_schema(schema)
31
- */
32
-
33
- VALUE cXMLSchema;
34
-
35
- // Rdoc needs to know
36
- #ifdef RDOC_NEVER_DEFINED
37
- mLibXML = rb_define_module("LibXML");
38
- mXML = rb_define_module_under(mLibXML, "XML");
39
- #endif
40
-
41
- static void rxml_schema_free(xmlSchemaPtr xschema)
42
- {
43
- xmlSchemaFree(xschema);
44
- }
45
-
46
- /*
47
- * call-seq:
48
- * XML::Schema.initialize(schema_uri) -> schema
49
- *
50
- * Create a new schema from the specified URI.
51
- */
52
- static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
53
- {
54
- xmlSchemaParserCtxtPtr xparser;
55
- xmlSchemaPtr xschema;
56
-
57
- Check_Type(uri, T_STRING);
58
-
59
- xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
60
- xschema = xmlSchemaParse(xparser);
61
- xmlSchemaFreeParserCtxt(xparser);
62
-
63
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
64
- }
65
-
66
- /*
67
- * call-seq:
68
- * XML::Schema.document(document) -> schema
69
- *
70
- * Create a new schema from the specified document.
71
- */
72
- static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
73
- {
74
- xmlDocPtr xdoc;
75
- xmlSchemaPtr xschema;
76
- xmlSchemaParserCtxtPtr xparser;
77
-
78
- Data_Get_Struct(document, xmlDoc, xdoc);
79
-
80
- xparser = xmlSchemaNewDocParserCtxt(xdoc);
81
- xschema = xmlSchemaParse(xparser);
82
- xmlSchemaFreeParserCtxt(xparser);
83
-
84
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
85
- }
86
-
87
- /*
88
- * call-seq:
89
- * XML::Schema.string("schema_data") -> "value"
90
- *
91
- * Create a new schema using the specified string.
92
- */
93
- static VALUE rxml_schema_init_from_string(VALUE self, VALUE schema_str)
94
- {
95
- xmlSchemaParserCtxtPtr xparser;
96
- xmlSchemaPtr xschema;
97
-
98
- Check_Type(schema_str, T_STRING);
99
-
100
- xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(
101
- StringValuePtr(schema_str)));
102
- xschema = xmlSchemaParse(xparser);
103
- xmlSchemaFreeParserCtxt(xparser);
104
-
105
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
106
- }
107
-
108
- /* TODO what is this patch doing here?
109
-
110
- xmlSchemaParserCtxtPtr parser;
111
- xmlSchemaPtr sptr;
112
- xmlSchemaValidCtxtPtr vptr;
113
- + int is_invalid;
114
-
115
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &source) == FAILURE) {
116
- return;
117
- @@ -598,26 +598,24 @@
118
- convert_to_string_ex(&source);
119
- parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source));
120
- sptr = xmlSchemaParse(parser);
121
- break;
122
- case SCHEMA_BLOB:
123
- convert_to_string_ex(&source);
124
- parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source), Z_STRLEN_P(source));
125
- sptr = xmlSchemaParse(parser);
126
- break;
127
- }
128
-
129
- vptr = xmlSchemaNewValidCtxt(sptr);
130
- + is_invalid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
131
- xmlSchemaFree(sptr);
132
- xmlSchemaFreeValidCtxt(vptr);
133
- xmlSchemaFreeParserCtxt(parser);
134
-
135
- - if (is_valid) {
136
- - RETURN_TRUE;
137
- - } else {
138
- + if (is_invalid) {
139
- RETURN_FALSE;
140
- + } else {
141
- + RETURN_TRUE;
142
- }
143
- }
144
- }}}
145
- @@ -695,7 +693,7 @@
146
- {
147
- if (!strcmp(method, "xsearch")) {
148
- simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU);
149
- -#ifdef xmlSchemaParserCtxtPtr
150
- +#ifdef LIBXML_SCHEMAS_ENABLED
151
- } else if (!strcmp(method, "validate_schema_file")) {
152
- simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_FILE);
153
- } else if (!strcmp(method, "validate_schema_buffer")) {
154
- */
155
-
156
- void ruby_init_xml_schema(void)
157
- {
158
- cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
159
- rb_define_singleton_method(cXMLSchema, "new", rxml_schema_init_from_uri, 1);
160
- rb_define_singleton_method(cXMLSchema, "from_string",
161
- rxml_schema_init_from_string, 1);
162
- rb_define_singleton_method(cXMLSchema, "document",
163
- rxml_schema_init_from_document, 1);
164
- }
165
-
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml_schema.h"
3
+
4
+ /*
5
+ * Document-class: LibXML::XML::Schema
6
+ *
7
+ * The XML::Schema class is used to prepare XML Schemas for validation of xml
8
+ * documents.
9
+ *
10
+ * Schemas can be created from XML documents, strings or URIs using the
11
+ * corresponding methods (new for URIs).
12
+ *
13
+ * Once a schema is prepared, an XML document can be validated by the
14
+ * XML::Document#validate_schema method providing the XML::Schema object
15
+ * as parameter. The method return true if the document validates, false
16
+ * otherwise.
17
+ *
18
+ * Basic usage:
19
+ *
20
+ * # parse schema as xml document
21
+ * schema_document = XML::Document.file('schema.rng')
22
+ *
23
+ * # prepare schema for validation
24
+ * schema = XML::Schema.document(schema_document)
25
+ *
26
+ * # parse xml document to be validated
27
+ * instance = XML::Document.file('instance.xml')
28
+ *
29
+ * # validate
30
+ * instance.validate_schema(schema)
31
+ */
32
+
33
+ VALUE cXMLSchema;
34
+
35
+ // Rdoc needs to know
36
+ #ifdef RDOC_NEVER_DEFINED
37
+ mLibXML = rb_define_module("LibXML");
38
+ mXML = rb_define_module_under(mLibXML, "XML");
39
+ #endif
40
+
41
+ static void rxml_schema_free(xmlSchemaPtr xschema)
42
+ {
43
+ xmlSchemaFree(xschema);
44
+ }
45
+
46
+ /*
47
+ * call-seq:
48
+ * XML::Schema.initialize(schema_uri) -> schema
49
+ *
50
+ * Create a new schema from the specified URI.
51
+ */
52
+ static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
53
+ {
54
+ xmlSchemaParserCtxtPtr xparser;
55
+ xmlSchemaPtr xschema;
56
+
57
+ Check_Type(uri, T_STRING);
58
+
59
+ xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
60
+ xschema = xmlSchemaParse(xparser);
61
+ xmlSchemaFreeParserCtxt(xparser);
62
+
63
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
64
+ }
65
+
66
+ /*
67
+ * call-seq:
68
+ * XML::Schema.document(document) -> schema
69
+ *
70
+ * Create a new schema from the specified document.
71
+ */
72
+ static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
73
+ {
74
+ xmlDocPtr xdoc;
75
+ xmlSchemaPtr xschema;
76
+ xmlSchemaParserCtxtPtr xparser;
77
+
78
+ Data_Get_Struct(document, xmlDoc, xdoc);
79
+
80
+ xparser = xmlSchemaNewDocParserCtxt(xdoc);
81
+ xschema = xmlSchemaParse(xparser);
82
+ xmlSchemaFreeParserCtxt(xparser);
83
+
84
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
85
+ }
86
+
87
+ /*
88
+ * call-seq:
89
+ * XML::Schema.string("schema_data") -> "value"
90
+ *
91
+ * Create a new schema using the specified string.
92
+ */
93
+ static VALUE rxml_schema_init_from_string(VALUE self, VALUE schema_str)
94
+ {
95
+ xmlSchemaParserCtxtPtr xparser;
96
+ xmlSchemaPtr xschema;
97
+
98
+ Check_Type(schema_str, T_STRING);
99
+
100
+ xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(
101
+ StringValuePtr(schema_str)));
102
+ xschema = xmlSchemaParse(xparser);
103
+ xmlSchemaFreeParserCtxt(xparser);
104
+
105
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
106
+ }
107
+
108
+ /* TODO what is this patch doing here?
109
+
110
+ xmlSchemaParserCtxtPtr parser;
111
+ xmlSchemaPtr sptr;
112
+ xmlSchemaValidCtxtPtr vptr;
113
+ + int is_invalid;
114
+
115
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &source) == FAILURE) {
116
+ return;
117
+ @@ -598,26 +598,24 @@
118
+ convert_to_string_ex(&source);
119
+ parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source));
120
+ sptr = xmlSchemaParse(parser);
121
+ break;
122
+ case SCHEMA_BLOB:
123
+ convert_to_string_ex(&source);
124
+ parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source), Z_STRLEN_P(source));
125
+ sptr = xmlSchemaParse(parser);
126
+ break;
127
+ }
128
+
129
+ vptr = xmlSchemaNewValidCtxt(sptr);
130
+ + is_invalid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
131
+ xmlSchemaFree(sptr);
132
+ xmlSchemaFreeValidCtxt(vptr);
133
+ xmlSchemaFreeParserCtxt(parser);
134
+
135
+ - if (is_valid) {
136
+ - RETURN_TRUE;
137
+ - } else {
138
+ + if (is_invalid) {
139
+ RETURN_FALSE;
140
+ + } else {
141
+ + RETURN_TRUE;
142
+ }
143
+ }
144
+ }}}
145
+ @@ -695,7 +693,7 @@
146
+ {
147
+ if (!strcmp(method, "xsearch")) {
148
+ simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU);
149
+ -#ifdef xmlSchemaParserCtxtPtr
150
+ +#ifdef LIBXML_SCHEMAS_ENABLED
151
+ } else if (!strcmp(method, "validate_schema_file")) {
152
+ simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_FILE);
153
+ } else if (!strcmp(method, "validate_schema_buffer")) {
154
+ */
155
+
156
+ void ruby_init_xml_schema(void)
157
+ {
158
+ cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
159
+ rb_define_singleton_method(cXMLSchema, "new", rxml_schema_init_from_uri, 1);
160
+ rb_define_singleton_method(cXMLSchema, "from_string",
161
+ rxml_schema_init_from_string, 1);
162
+ rb_define_singleton_method(cXMLSchema, "document",
163
+ rxml_schema_init_from_document, 1);
164
+ }
165
+