libxml-ruby 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/CHANGES +21 -0
  2. data/RAKEFILE +213 -0
  3. data/README +32 -11
  4. data/doc/rdoc/classes/LibXML.html +4 -0
  5. data/doc/rdoc/classes/LibXML/XML.html +7 -0
  6. data/doc/rdoc/classes/LibXML/XML/Attr.html +187 -177
  7. data/doc/rdoc/classes/LibXML/XML/Attributes.html +62 -61
  8. data/doc/rdoc/classes/LibXML/XML/Document.html +318 -254
  9. data/doc/rdoc/classes/LibXML/XML/Dtd.html +62 -8
  10. data/doc/rdoc/classes/LibXML/XML/Error.html +6 -0
  11. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +59 -41
  12. data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +12 -6
  13. data/doc/rdoc/classes/LibXML/XML/NS.html +65 -50
  14. data/doc/rdoc/classes/LibXML/XML/Node.html +671 -630
  15. data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +12 -0
  16. data/doc/rdoc/classes/LibXML/XML/Node/Set.html +64 -60
  17. data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +12 -0
  18. data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +12 -0
  19. data/doc/rdoc/classes/LibXML/XML/Parser.html +407 -383
  20. data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +241 -219
  21. data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +12 -0
  22. data/doc/rdoc/classes/LibXML/XML/Reader.html +421 -331
  23. data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +237 -0
  24. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +79 -60
  25. data/doc/rdoc/classes/LibXML/XML/Schema.html +109 -22
  26. data/doc/rdoc/classes/LibXML/XML/State.html +6 -0
  27. data/doc/rdoc/classes/LibXML/XML/XInclude.html +6 -0
  28. data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +6 -0
  29. data/doc/rdoc/classes/LibXML/XML/XPath.html +4 -48
  30. data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +6 -5
  31. data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +61 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +12 -8
  33. data/doc/rdoc/classes/LibXML/XML/XPointer.html +14 -8
  34. data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +6 -0
  35. data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +6 -0
  36. data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +13 -0
  37. data/doc/rdoc/created.rid +1 -1
  38. data/doc/rdoc/files/CHANGES.html +38 -10
  39. data/doc/rdoc/files/LICENSE.html +1 -1
  40. data/doc/rdoc/files/README.html +57 -23
  41. data/doc/rdoc/files/VERSION.html +1 -1
  42. data/doc/rdoc/files/ext/libxml/cbg_c.html +1 -1
  43. data/doc/rdoc/files/ext/libxml/libxml_c.html +1 -1
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +1 -1
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +1 -1
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
  56. data/doc/rdoc/{classes/XML.html → files/ext/libxml/ruby_xml_relaxng_c.html} +16 -35
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +1 -1
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
  66. data/doc/rdoc/files/lib/libxml/attr_rb.html +1 -1
  67. data/doc/rdoc/files/lib/libxml/attributes_rb.html +1 -1
  68. data/doc/rdoc/files/lib/libxml/document_rb.html +1 -1
  69. data/doc/rdoc/files/lib/libxml/node_rb.html +1 -1
  70. data/doc/rdoc/files/lib/libxml/node_set_rb.html +1 -1
  71. data/doc/rdoc/files/lib/libxml/parser_options_rb.html +1 -1
  72. data/doc/rdoc/files/lib/libxml/parser_rb.html +1 -1
  73. data/doc/rdoc/files/lib/libxml/properties_rb.html +1 -1
  74. data/doc/rdoc/files/lib/libxml/tree_rb.html +1 -1
  75. data/doc/rdoc/files/lib/libxml_rb.html +2 -2
  76. data/doc/rdoc/files/lib/xml/libxml_rb.html +12 -2
  77. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  78. data/doc/rdoc/fr_class_index.html +1 -1
  79. data/doc/rdoc/fr_file_index.html +2 -0
  80. data/doc/rdoc/fr_method_index.html +349 -344
  81. data/ext/libxml/libxml.c +2 -1
  82. data/ext/libxml/ruby_libxml.h +1 -0
  83. data/ext/libxml/ruby_xml_attr.c +8 -2
  84. data/ext/libxml/ruby_xml_attributes.c +5 -5
  85. data/ext/libxml/ruby_xml_document.c +41 -2
  86. data/ext/libxml/ruby_xml_dtd.c +169 -169
  87. data/ext/libxml/ruby_xml_html_parser.c +449 -449
  88. data/ext/libxml/ruby_xml_input_cbg.c +165 -165
  89. data/ext/libxml/ruby_xml_node.c +1 -1
  90. data/ext/libxml/ruby_xml_node_set.c +172 -172
  91. data/ext/libxml/ruby_xml_ns.c +145 -145
  92. data/ext/libxml/ruby_xml_parser.c +1398 -1398
  93. data/ext/libxml/ruby_xml_parser_context.c +697 -697
  94. data/ext/libxml/ruby_xml_reader.c +44 -0
  95. data/ext/libxml/ruby_xml_reader.h +14 -14
  96. data/ext/libxml/ruby_xml_relaxng.c +97 -0
  97. data/ext/libxml/ruby_xml_relaxng.h +15 -0
  98. data/ext/libxml/ruby_xml_sax_parser.c +486 -486
  99. data/ext/libxml/ruby_xml_schema.c +1 -1
  100. data/ext/libxml/ruby_xml_state.c +4 -4
  101. data/ext/libxml/ruby_xml_xinclude.c +21 -21
  102. data/ext/libxml/ruby_xml_xpath.c +89 -89
  103. data/ext/libxml/ruby_xml_xpath_context.c +283 -283
  104. data/ext/libxml/ruby_xml_xpath_object.c +5 -5
  105. data/ext/libxml/ruby_xml_xpointer.c +104 -104
  106. data/ext/libxml/ruby_xml_xpointer_context.c +22 -22
  107. data/ext/libxml/version.h +2 -2
  108. data/ext/libxml/version.h.rej +17 -0
  109. data/ext/mingw/Rakefile +41 -0
  110. data/lib/libxml.rb +15 -4
  111. data/lib/xml.rb +14 -0
  112. data/lib/xml/libxml.rb +4 -1
  113. data/test/etc_doc_to_s.rb +1 -1
  114. data/test/ets_copy_bug.rb +1 -1
  115. data/test/ets_copy_bug3.rb +1 -1
  116. data/test/ets_doc_file.rb +1 -1
  117. data/test/ets_doc_to_s.rb +1 -1
  118. data/test/ets_node_gc.rb +1 -1
  119. data/test/ets_tsr.rb +1 -1
  120. data/test/model/shiporder.rnc +28 -0
  121. data/test/model/shiporder.rng +86 -0
  122. data/test/{tc_xml_attributes.rb → tc_attributes.rb} +1 -10
  123. data/test/{tc_xml_document.rb → tc_document.rb} +1 -1
  124. data/test/{tc_xml_document_write.rb → tc_document_write.rb} +1 -1
  125. data/test/{tc_xml_dtd.rb → tc_dtd.rb} +1 -1
  126. data/test/{tc_xml_html_parser.rb → tc_html_parser.rb} +1 -1
  127. data/test/{tc_xml_node.rb → tc_node.rb} +1 -1
  128. data/test/{tc_xml_node_attr.rb → tc_node_attr.rb} +1 -1
  129. data/test/{tc_xml_node_cdata.rb → tc_node_cdata.rb} +24 -5
  130. data/test/{tc_xml_node_comment.rb → tc_node_comment.rb} +1 -1
  131. data/test/{tc_xml_node_copy.rb → tc_node_copy.rb} +1 -1
  132. data/test/{tc_xml_node_edit.rb → tc_node_edit.rb} +1 -1
  133. data/test/{tc_xml_node_set.rb → tc_node_set.rb} +1 -1
  134. data/test/{tc_xml_node_set2.rb → tc_node_set2.rb} +1 -1
  135. data/test/{tc_xml_node_text.rb → tc_node_text.rb} +1 -1
  136. data/test/{tc_xml_node_xlink.rb → tc_node_xlink.rb} +2 -2
  137. data/test/{tc_xml_parser.rb → tc_parser.rb} +1 -1
  138. data/test/{tc_xml_parser_context.rb → tc_parser_context.rb} +1 -1
  139. data/test/{tc_xml_properties.rb → tc_properties.rb} +1 -7
  140. data/test/{tc_xml_reader.rb → tc_reader.rb} +1 -1
  141. data/test/tc_relaxng.rb +39 -0
  142. data/test/{tc_xml_sax_parser.rb → tc_sax_parser.rb} +1 -1
  143. data/test/{tc_xml_schema.rb → tc_schema.rb} +1 -1
  144. data/test/{tc_xml_traversal.rb → tc_traversal.rb} +1 -1
  145. data/test/{tc_xml_xinclude.rb → tc_xinclude.rb} +1 -1
  146. data/test/{tc_xml_xpath.rb → tc_xpath.rb} +1 -1
  147. data/test/{tc_xml_xpath_context.rb → tc_xpath_context.rb} +1 -1
  148. data/test/{tc_xml_xpointer.rb → tc_xpointer.rb} +1 -1
  149. data/test/test_suite.rb +26 -25
  150. metadata +100 -100
  151. data/benchmark/depixelate.rb +0 -632
  152. data/benchmark/hamlet.xml +0 -9055
  153. data/benchmark/sock_entries.xml +0 -507
  154. data/benchmark/throughput.rb +0 -39
  155. data/benchmark/xml_benchmarks.rb +0 -227
  156. data/mingw/libiconv-2.dll +0 -0
  157. data/mingw/libxml2-2.dll +0 -0
  158. data/mingw/libxml_ruby.so +0 -0
  159. data/test/gc.log +0 -0
  160. data/vc/libxml_ruby.sln +0 -20
  161. data/vc/libxml_ruby.vcproj +0 -389
@@ -1,4 +1,4 @@
1
- /* $Id: libxml.c 462 2008-07-15 21:52:47Z cfis $ */
1
+ /* $Id: libxml.c 489 2008-07-21 22:41:11Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -52,6 +52,7 @@ Init_libxml_ruby(void) {
52
52
  ruby_init_input_callbacks();
53
53
  ruby_init_xml_dtd();
54
54
  ruby_init_xml_schema();
55
+ ruby_init_xml_relaxng();
55
56
  ruby_init_xml_reader();
56
57
 
57
58
  ruby_xml_parser_default_substitute_entities_set(cXMLParser, Qtrue);
@@ -81,6 +81,7 @@ typedef struct rx_xpath_data {
81
81
  #include "ruby_xml_input_cbg.h"
82
82
  #include "ruby_xml_dtd.h"
83
83
  #include "ruby_xml_schema.h"
84
+ #include "ruby_xml_relaxng.h"
84
85
  #include "ruby_xml_html_parser.h"
85
86
  #include "ruby_xml_reader.h"
86
87
 
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_attr.c 461 2008-07-15 21:35:56Z cfis $ */
1
+ /* $Id: ruby_xml_attr.c 502 2008-07-22 01:45:31Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -9,7 +9,7 @@
9
9
  * calling XML::Node#attributes method.
10
10
  *
11
11
  * Basic Usage:
12
- * require 'libxml'
12
+ * require 'xml'
13
13
  *
14
14
  * doc = XML::Document.new(<some_file>)
15
15
  * attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
@@ -109,6 +109,9 @@ ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {
109
109
  Check_Type(value, T_STRING);
110
110
 
111
111
  Data_Get_Struct(node, xmlNode, xnode);
112
+
113
+ if (xnode->type != XML_ELEMENT_NODE)
114
+ rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
112
115
 
113
116
  if NIL_P(ns)
114
117
  {
@@ -120,6 +123,9 @@ ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {
120
123
  Data_Get_Struct(ns, xmlNs, xns);
121
124
  xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
122
125
  }
126
+
127
+ if (!xattr)
128
+ rb_raise(rb_eRuntimeError, "Could not create attribute.");
123
129
 
124
130
  xattr->_private = (void *)self;
125
131
  DATA_PTR(self) = xattr;
@@ -8,7 +8,7 @@
8
8
  * Provides access to an elements attributes (XML::Attr).
9
9
  *
10
10
  * Basic Usage:
11
- * require 'libxml'
11
+ * require 'xml'
12
12
  *
13
13
  * doc = XML::Document.new(<some_file>)
14
14
  * attributes = doc.root.attributes
@@ -249,10 +249,10 @@ ruby_xml_attributes_first(VALUE self) {
249
249
  }
250
250
 
251
251
  // Rdoc needs to know
252
- #ifdef RDOC_NEVER_DEFINED
253
- mLibXML = rb_define_module("LibXML");
254
- mXML = rb_define_module_under(mLibXML, "XML");
255
- #endif
252
+ #ifdef RDOC_NEVER_DEFINED
253
+ mLibXML = rb_define_module("LibXML");
254
+ mXML = rb_define_module_under(mLibXML, "XML");
255
+ #endif
256
256
 
257
257
  void
258
258
  ruby_init_xml_attributes(void) {
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_document.c 461 2008-07-15 21:35:56Z cfis $ */
1
+ /* $Id: ruby_xml_document.c 502 2008-07-22 01:45:31Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -8,7 +8,7 @@
8
8
  * Reads or writes an XML document:
9
9
  *
10
10
  * Reading:
11
- * require 'libxml'
11
+ * require 'xml'
12
12
  *
13
13
  * doc = XML::Document.new()
14
14
  * doc.root = XML::Node.new('root_node')
@@ -932,6 +932,10 @@ LibXML_validity_warning(void * ctxt, const char * msg, va_list ap)
932
932
  * document.validate_schema(schema) -> (true|false)
933
933
  *
934
934
  * Validate this document against the specified XML::Schema.
935
+ *
936
+ * If a block is provided it is used as an error handler for validaten errors.
937
+ * The block is called with two argument, the message and a flag indication
938
+ * if the message is an error (true) or a warning (false).
935
939
  */
936
940
  VALUE
937
941
  ruby_xml_document_validate_schema(VALUE self, VALUE schema) {
@@ -957,6 +961,40 @@ ruby_xml_document_validate_schema(VALUE self, VALUE schema) {
957
961
  }
958
962
  }
959
963
 
964
+ /*
965
+ * call-seq:
966
+ * document.validate_schema(relaxng) -> (true|false)
967
+ *
968
+ * Validate this document against the specified XML::RelaxNG.
969
+ *
970
+ * If a block is provided it is used as an error handler for validaten errors.
971
+ * The block is called with two argument, the message and a flag indication
972
+ * if the message is an error (true) or a warning (false).
973
+ */
974
+ VALUE
975
+ ruby_xml_document_validate_relaxng(VALUE self, VALUE relaxng) {
976
+ xmlRelaxNGValidCtxtPtr vptr;
977
+ ruby_xml_document_t *c_doc;
978
+ ruby_xml_relaxng *c_relaxng;
979
+ int is_invalid;
980
+
981
+ Data_Get_Struct(self, ruby_xml_document_t, c_doc);
982
+ Data_Get_Struct(relaxng, ruby_xml_relaxng, c_relaxng);
983
+
984
+ vptr = xmlRelaxNGNewValidCtxt(c_relaxng->relaxng);
985
+
986
+ xmlRelaxNGSetValidErrors(vptr, (xmlRelaxNGValidityErrorFunc)LibXML_validity_error,
987
+ (xmlRelaxNGValidityWarningFunc)LibXML_validity_warning, NULL);
988
+
989
+ is_invalid = xmlRelaxNGValidateDoc(vptr, c_doc->doc);
990
+ xmlRelaxNGFreeValidCtxt(vptr);
991
+ if (is_invalid) {
992
+ return Qfalse;
993
+ } else {
994
+ return Qtrue;
995
+ }
996
+ }
997
+
960
998
 
961
999
  /*
962
1000
  * call-seq:
@@ -1092,5 +1130,6 @@ ruby_init_xml_document(void) {
1092
1130
  rb_define_method(cXMLDocument, "xinclude", ruby_xml_document_xinclude, 0);
1093
1131
  rb_define_method(cXMLDocument, "validate", ruby_xml_document_validate_dtd, 1);
1094
1132
  rb_define_method(cXMLDocument, "validate_schema", ruby_xml_document_validate_schema, 1);
1133
+ rb_define_method(cXMLDocument, "validate_relaxng", ruby_xml_document_validate_relaxng, 1);
1095
1134
  rb_define_method(cXMLDocument, "reader", ruby_xml_document_reader, 0);
1096
1135
  }
@@ -1,169 +1,169 @@
1
- #include "ruby_libxml.h"
2
- #include "ruby_xml_dtd.h"
3
-
4
- VALUE cXMLDtd;
5
-
6
- void
7
- ruby_xml_dtd_free(ruby_xml_dtd *rxdtd) {
8
- if (rxdtd->dtd != NULL) {
9
- xmlFreeDtd(rxdtd->dtd);
10
- rxdtd->dtd = NULL;
11
- }
12
-
13
- ruby_xfree(rxdtd);
14
- }
15
-
16
- static void
17
- ruby_xml_dtd_mark(ruby_xml_dtd *rxdtd) {
18
- return;
19
- //if (rxdtd == NULL) return;
20
- //if (!NIL_P(rxd->xmlver)) rb_gc_mark(rxd->xmlver);
21
- }
22
-
23
- /*
24
- * call-seq:
25
- * XML::Dtd.new("public system") -> dtd
26
- * XML::Dtd.new("public", "system") -> dtd
27
- *
28
- * Create a new Dtd from the specified public and system
29
- * identifiers.
30
- */
31
- VALUE
32
- ruby_xml_dtd_initialize(int argc, VALUE *argv, VALUE class) {
33
- ruby_xml_dtd *rxdtd;
34
- VALUE external, system, dtd_string;
35
- xmlParserInputBufferPtr buffer;
36
- xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
37
- xmlChar *new_string;
38
-
39
- // 1 argument -- string --> parsujeme jako dtd
40
- // 2 argumenty -- public, system --> bude se hledat
41
- switch (argc) {
42
- case 2:
43
- rb_scan_args(argc, argv, "20", &external, &system);
44
-
45
- Check_Type(external, T_STRING);
46
- Check_Type(system, T_STRING);
47
- rxdtd = ALLOC(ruby_xml_dtd);
48
- rxdtd->dtd = xmlParseDTD( (xmlChar*)StringValuePtr(external),
49
- (xmlChar*)StringValuePtr(system) );
50
- if (rxdtd->dtd == NULL) {
51
- ruby_xfree(rxdtd);
52
- return(Qfalse);
53
- }
54
-
55
- xmlSetTreeDoc( (xmlNodePtr)rxdtd->dtd, NULL );
56
- return( Data_Wrap_Struct(cXMLDtd, ruby_xml_dtd_mark, ruby_xml_dtd_free, rxdtd) );
57
- break;
58
-
59
- /*
60
- SV *
61
- new(CLASS, external, system)
62
- char * CLASS
63
- char * external
64
- char * system
65
- ALIAS:
66
- parse_uri = 1
67
- PREINIT:
68
- xmlDtdPtr dtd = NULL;
69
- CODE:
70
- LibXML_error = sv_2mortal(newSVpv("", 0));
71
- dtd = xmlParseDTD((const xmlChar*)external, (const xmlChar*)system);
72
- if ( dtd == NULL ) {
73
- XSRETURN_UNDEF;
74
- }
75
- xmlSetTreeDoc((xmlNodePtr)dtd, NULL);
76
- RETVAL = PmmNodeToSv( (xmlNodePtr) dtd, NULL );
77
- OUTPUT:
78
- RETVAL
79
- */
80
-
81
- case 1:
82
-
83
- rb_scan_args(argc, argv, "10", &dtd_string);
84
- buffer = xmlAllocParserInputBuffer(enc);
85
- //if ( !buffer) return Qnil
86
- new_string = xmlStrdup((xmlChar*)StringValuePtr(dtd_string));
87
- xmlParserInputBufferPush(buffer, xmlStrlen(new_string), (const char*)new_string);
88
-
89
- rxdtd = ALLOC(ruby_xml_dtd);
90
- rxdtd->dtd = xmlIOParseDTD(NULL, buffer, enc);
91
-
92
- // NOTE: For some reason freeing this InputBuffer causes a segfault!
93
- // xmlFreeParserInputBuffer(buffer);
94
- xmlFree(new_string);
95
-
96
- return( Data_Wrap_Struct(cXMLDtd, ruby_xml_dtd_mark, ruby_xml_dtd_free, rxdtd) );
97
-
98
- break;
99
- /*
100
- SV * parse_string(CLASS, str, ...)
101
- char * CLASS
102
- char * str
103
- PREINIT:
104
- STRLEN n_a;
105
- xmlDtdPtr res;
106
- SV * encoding_sv;
107
- xmlParserInputBufferPtr buffer;
108
- xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
109
- xmlChar * new_string;
110
- STRLEN len;
111
- CODE:
112
- LibXML_init_error();
113
- if (items > 2) {
114
- encoding_sv = ST(2);
115
- if (items > 3) {
116
- croak("parse_string: too many parameters");
117
- }
118
- // warn("getting encoding...\n");
119
- enc = xmlParseCharEncoding(SvPV(encoding_sv, n_a));
120
- if (enc == XML_CHAR_ENCODING_ERROR) {
121
- croak("Parse of encoding %s failed: %s", SvPV(encoding_sv, n_a), SvPV(LibXML_error, n_a));
122
- }
123
- }
124
- buffer = xmlAllocParserInputBuffer(enc);
125
- // buffer = xmlParserInputBufferCreateMem(str, xmlStrlen(str), enc);
126
- if ( !buffer)
127
- croak("cant create buffer!\n" );
128
-
129
- new_string = xmlStrdup((const xmlChar*)str);
130
- xmlParserInputBufferPush(buffer, xmlStrlen(new_string), (const char*)new_string);
131
-
132
- res = xmlIOParseDTD(NULL, buffer, enc);
133
-
134
- // NOTE: For some reason freeing this InputBuffer causes a segfault!
135
- // xmlFreeParserInputBuffer(buffer);
136
- xmlFree(new_string);
137
-
138
- sv_2mortal( LibXML_error );
139
- LibXML_croak_error();
140
-
141
- if (res == NULL) {
142
- croak("no DTD parsed!");
143
- }
144
- RETVAL = PmmNodeToSv((xmlNodePtr)res, NULL);
145
- OUTPUT:
146
- RETVAL
147
- */
148
-
149
- default:
150
- rb_raise(rb_eArgError, "wrong number of arguments (need 1 or 2)");
151
- }
152
-
153
- //docobj = ruby_xml_document_new2(cXMLDocument, xmlver);
154
- return Qnil;
155
- }
156
-
157
- // Rdoc needs to know
158
- #ifdef RDOC_NEVER_DEFINED
159
- mLibXML = rb_define_module("LibXML");
160
- mXML = rb_define_module_under(mLibXML, "XML");
161
- #endif
162
-
163
- void
164
- ruby_init_xml_dtd(void) {
165
- cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
166
- rb_define_singleton_method(cXMLDtd, "new", ruby_xml_dtd_initialize, -1);
167
- //rb_define_method(cXMLDocument, "xinclude", ruby_xml_document_xinclude, 0);
168
- }
169
-
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml_dtd.h"
3
+
4
+ VALUE cXMLDtd;
5
+
6
+ void
7
+ ruby_xml_dtd_free(ruby_xml_dtd *rxdtd) {
8
+ if (rxdtd->dtd != NULL) {
9
+ xmlFreeDtd(rxdtd->dtd);
10
+ rxdtd->dtd = NULL;
11
+ }
12
+
13
+ ruby_xfree(rxdtd);
14
+ }
15
+
16
+ static void
17
+ ruby_xml_dtd_mark(ruby_xml_dtd *rxdtd) {
18
+ return;
19
+ //if (rxdtd == NULL) return;
20
+ //if (!NIL_P(rxd->xmlver)) rb_gc_mark(rxd->xmlver);
21
+ }
22
+
23
+ /*
24
+ * call-seq:
25
+ * XML::Dtd.new("public system") -> dtd
26
+ * XML::Dtd.new("public", "system") -> dtd
27
+ *
28
+ * Create a new Dtd from the specified public and system
29
+ * identifiers.
30
+ */
31
+ VALUE
32
+ ruby_xml_dtd_initialize(int argc, VALUE *argv, VALUE class) {
33
+ ruby_xml_dtd *rxdtd;
34
+ VALUE external, system, dtd_string;
35
+ xmlParserInputBufferPtr buffer;
36
+ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
37
+ xmlChar *new_string;
38
+
39
+ // 1 argument -- string --> parsujeme jako dtd
40
+ // 2 argumenty -- public, system --> bude se hledat
41
+ switch (argc) {
42
+ case 2:
43
+ rb_scan_args(argc, argv, "20", &external, &system);
44
+
45
+ Check_Type(external, T_STRING);
46
+ Check_Type(system, T_STRING);
47
+ rxdtd = ALLOC(ruby_xml_dtd);
48
+ rxdtd->dtd = xmlParseDTD( (xmlChar*)StringValuePtr(external),
49
+ (xmlChar*)StringValuePtr(system) );
50
+ if (rxdtd->dtd == NULL) {
51
+ ruby_xfree(rxdtd);
52
+ return(Qfalse);
53
+ }
54
+
55
+ xmlSetTreeDoc( (xmlNodePtr)rxdtd->dtd, NULL );
56
+ return( Data_Wrap_Struct(cXMLDtd, ruby_xml_dtd_mark, ruby_xml_dtd_free, rxdtd) );
57
+ break;
58
+
59
+ /*
60
+ SV *
61
+ new(CLASS, external, system)
62
+ char * CLASS
63
+ char * external
64
+ char * system
65
+ ALIAS:
66
+ parse_uri = 1
67
+ PREINIT:
68
+ xmlDtdPtr dtd = NULL;
69
+ CODE:
70
+ LibXML_error = sv_2mortal(newSVpv("", 0));
71
+ dtd = xmlParseDTD((const xmlChar*)external, (const xmlChar*)system);
72
+ if ( dtd == NULL ) {
73
+ XSRETURN_UNDEF;
74
+ }
75
+ xmlSetTreeDoc((xmlNodePtr)dtd, NULL);
76
+ RETVAL = PmmNodeToSv( (xmlNodePtr) dtd, NULL );
77
+ OUTPUT:
78
+ RETVAL
79
+ */
80
+
81
+ case 1:
82
+
83
+ rb_scan_args(argc, argv, "10", &dtd_string);
84
+ buffer = xmlAllocParserInputBuffer(enc);
85
+ //if ( !buffer) return Qnil
86
+ new_string = xmlStrdup((xmlChar*)StringValuePtr(dtd_string));
87
+ xmlParserInputBufferPush(buffer, xmlStrlen(new_string), (const char*)new_string);
88
+
89
+ rxdtd = ALLOC(ruby_xml_dtd);
90
+ rxdtd->dtd = xmlIOParseDTD(NULL, buffer, enc);
91
+
92
+ // NOTE: For some reason freeing this InputBuffer causes a segfault!
93
+ // xmlFreeParserInputBuffer(buffer);
94
+ xmlFree(new_string);
95
+
96
+ return( Data_Wrap_Struct(cXMLDtd, ruby_xml_dtd_mark, ruby_xml_dtd_free, rxdtd) );
97
+
98
+ break;
99
+ /*
100
+ SV * parse_string(CLASS, str, ...)
101
+ char * CLASS
102
+ char * str
103
+ PREINIT:
104
+ STRLEN n_a;
105
+ xmlDtdPtr res;
106
+ SV * encoding_sv;
107
+ xmlParserInputBufferPtr buffer;
108
+ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
109
+ xmlChar * new_string;
110
+ STRLEN len;
111
+ CODE:
112
+ LibXML_init_error();
113
+ if (items > 2) {
114
+ encoding_sv = ST(2);
115
+ if (items > 3) {
116
+ croak("parse_string: too many parameters");
117
+ }
118
+ // warn("getting encoding...\n");
119
+ enc = xmlParseCharEncoding(SvPV(encoding_sv, n_a));
120
+ if (enc == XML_CHAR_ENCODING_ERROR) {
121
+ croak("Parse of encoding %s failed: %s", SvPV(encoding_sv, n_a), SvPV(LibXML_error, n_a));
122
+ }
123
+ }
124
+ buffer = xmlAllocParserInputBuffer(enc);
125
+ // buffer = xmlParserInputBufferCreateMem(str, xmlStrlen(str), enc);
126
+ if ( !buffer)
127
+ croak("cant create buffer!\n" );
128
+
129
+ new_string = xmlStrdup((const xmlChar*)str);
130
+ xmlParserInputBufferPush(buffer, xmlStrlen(new_string), (const char*)new_string);
131
+
132
+ res = xmlIOParseDTD(NULL, buffer, enc);
133
+
134
+ // NOTE: For some reason freeing this InputBuffer causes a segfault!
135
+ // xmlFreeParserInputBuffer(buffer);
136
+ xmlFree(new_string);
137
+
138
+ sv_2mortal( LibXML_error );
139
+ LibXML_croak_error();
140
+
141
+ if (res == NULL) {
142
+ croak("no DTD parsed!");
143
+ }
144
+ RETVAL = PmmNodeToSv((xmlNodePtr)res, NULL);
145
+ OUTPUT:
146
+ RETVAL
147
+ */
148
+
149
+ default:
150
+ rb_raise(rb_eArgError, "wrong number of arguments (need 1 or 2)");
151
+ }
152
+
153
+ //docobj = ruby_xml_document_new2(cXMLDocument, xmlver);
154
+ return Qnil;
155
+ }
156
+
157
+ // Rdoc needs to know
158
+ #ifdef RDOC_NEVER_DEFINED
159
+ mLibXML = rb_define_module("LibXML");
160
+ mXML = rb_define_module_under(mLibXML, "XML");
161
+ #endif
162
+
163
+ void
164
+ ruby_init_xml_dtd(void) {
165
+ cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
166
+ rb_define_singleton_method(cXMLDtd, "new", ruby_xml_dtd_initialize, -1);
167
+ //rb_define_method(cXMLDocument, "xinclude", ruby_xml_document_xinclude, 0);
168
+ }
169
+