libxml-ruby 0.6.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/CHANGES +122 -0
  2. data/LICENSE +23 -0
  3. data/README +144 -0
  4. data/ext/libxml/cbg.c +76 -0
  5. data/ext/libxml/extconf.rb +308 -0
  6. data/ext/libxml/libxml.c +62 -0
  7. data/ext/libxml/ruby_libxml.h +93 -0
  8. data/ext/libxml/ruby_xml_attr.c +405 -0
  9. data/ext/libxml/ruby_xml_attr.h +19 -0
  10. data/ext/libxml/ruby_xml_document.c +1111 -0
  11. data/ext/libxml/ruby_xml_document.h +27 -0
  12. data/ext/libxml/ruby_xml_dtd.c +168 -0
  13. data/ext/libxml/ruby_xml_dtd.h +17 -0
  14. data/ext/libxml/ruby_xml_html_parser.c +449 -0
  15. data/ext/libxml/ruby_xml_html_parser.h +29 -0
  16. data/ext/libxml/ruby_xml_input_cbg.c +158 -0
  17. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  18. data/ext/libxml/ruby_xml_node.c +2410 -0
  19. data/ext/libxml/ruby_xml_node.h +27 -0
  20. data/ext/libxml/ruby_xml_node_set.c +170 -0
  21. data/ext/libxml/ruby_xml_node_set.h +20 -0
  22. data/ext/libxml/ruby_xml_ns.c +153 -0
  23. data/ext/libxml/ruby_xml_ns.h +21 -0
  24. data/ext/libxml/ruby_xml_parser.c +1425 -0
  25. data/ext/libxml/ruby_xml_parser.h +31 -0
  26. data/ext/libxml/ruby_xml_parser_context.c +750 -0
  27. data/ext/libxml/ruby_xml_parser_context.h +22 -0
  28. data/ext/libxml/ruby_xml_reader.c +900 -0
  29. data/ext/libxml/ruby_xml_reader.h +14 -0
  30. data/ext/libxml/ruby_xml_sax_parser.c +485 -0
  31. data/ext/libxml/ruby_xml_sax_parser.h +56 -0
  32. data/ext/libxml/ruby_xml_schema.c +146 -0
  33. data/ext/libxml/ruby_xml_schema.h +16 -0
  34. data/ext/libxml/ruby_xml_state.c +113 -0
  35. data/ext/libxml/ruby_xml_state.h +12 -0
  36. data/ext/libxml/ruby_xml_tree.c +43 -0
  37. data/ext/libxml/ruby_xml_tree.h +12 -0
  38. data/ext/libxml/ruby_xml_xinclude.c +20 -0
  39. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  40. data/ext/libxml/ruby_xml_xpath.c +243 -0
  41. data/ext/libxml/ruby_xml_xpath.h +23 -0
  42. data/ext/libxml/ruby_xml_xpath_context.c +118 -0
  43. data/ext/libxml/ruby_xml_xpath_context.h +20 -0
  44. data/ext/libxml/ruby_xml_xpath_object.c +293 -0
  45. data/ext/libxml/ruby_xml_xpath_object.h +28 -0
  46. data/ext/libxml/ruby_xml_xpointer.c +100 -0
  47. data/ext/libxml/ruby_xml_xpointer.h +27 -0
  48. data/ext/libxml/ruby_xml_xpointer_context.c +21 -0
  49. data/ext/libxml/ruby_xml_xpointer_context.h +18 -0
  50. data/ext/libxml/sax_parser_callbacks.inc +213 -0
  51. data/ext/libxml/version.h +9 -0
  52. data/lib/libxml.rb +125 -0
  53. data/lib/libxml_ruby.so +0 -0
  54. data/lib/xml/libxml.rb +5 -0
  55. data/mingw/libiconv-2.dll +0 -0
  56. data/mingw/libxml2-2.dll +0 -0
  57. data/mingw/libxml_ruby.so +0 -0
  58. data/mingw/mingw.rake +36 -0
  59. data/test/dtd-test.rb +24 -0
  60. data/test/etc_doc_to_s.rb +19 -0
  61. data/test/ets_copy_bug.rb +21 -0
  62. data/test/ets_copy_bug2.rb +32 -0
  63. data/test/ets_copy_bug3.rb +38 -0
  64. data/test/ets_doc_file.rb +15 -0
  65. data/test/ets_doc_to_s.rb +21 -0
  66. data/test/ets_gpx.rb +26 -0
  67. data/test/ets_node_gc.rb +21 -0
  68. data/test/ets_test.xml +2 -0
  69. data/test/ets_tsr.rb +9 -0
  70. data/test/gc.log +0 -0
  71. data/test/merge_bug.rb +55 -0
  72. data/test/schema-test.rb +74 -0
  73. data/test/tc_well_formed.rb +11 -0
  74. data/test/tc_xml_document.rb +52 -0
  75. data/test/tc_xml_document_write.rb +24 -0
  76. data/test/tc_xml_document_write2.rb +54 -0
  77. data/test/tc_xml_document_write3.rb +96 -0
  78. data/test/tc_xml_html_parser.rb +63 -0
  79. data/test/tc_xml_node.rb +59 -0
  80. data/test/tc_xml_node2.rb +25 -0
  81. data/test/tc_xml_node3.rb +27 -0
  82. data/test/tc_xml_node4.rb +86 -0
  83. data/test/tc_xml_node5.rb +52 -0
  84. data/test/tc_xml_node6.rb +27 -0
  85. data/test/tc_xml_node7.rb +35 -0
  86. data/test/tc_xml_node8.rb +32 -0
  87. data/test/tc_xml_node9.rb +32 -0
  88. data/test/tc_xml_node_copy.rb +40 -0
  89. data/test/tc_xml_node_set.rb +24 -0
  90. data/test/tc_xml_node_set2.rb +37 -0
  91. data/test/tc_xml_node_text.rb +17 -0
  92. data/test/tc_xml_node_xlink.rb +28 -0
  93. data/test/tc_xml_parser.rb +190 -0
  94. data/test/tc_xml_parser2.rb +16 -0
  95. data/test/tc_xml_parser3.rb +23 -0
  96. data/test/tc_xml_parser4.rb +33 -0
  97. data/test/tc_xml_parser5.rb +27 -0
  98. data/test/tc_xml_parser6.rb +23 -0
  99. data/test/tc_xml_parser7.rb +28 -0
  100. data/test/tc_xml_parser8.rb +32 -0
  101. data/test/tc_xml_parser9.rb +11 -0
  102. data/test/tc_xml_parser_context.rb +88 -0
  103. data/test/tc_xml_reader.rb +112 -0
  104. data/test/tc_xml_sax_parser.rb +104 -0
  105. data/test/tc_xml_sax_parser2.rb +51 -0
  106. data/test/tc_xml_xinclude.rb +30 -0
  107. data/test/tc_xml_xpath.rb +38 -0
  108. data/test/tc_xml_xpath2.rb +14 -0
  109. data/test/tc_xml_xpointer.rb +78 -0
  110. data/vc/libxml.sln +20 -0
  111. data/vc/libxml.vcproj +389 -0
  112. data/work/Rakefile +247 -0
  113. data/work/task/make +26 -0
  114. data/work/task/memory +37 -0
  115. data/work/task/rdoc +39 -0
  116. data/work/task/setup +1616 -0
  117. data/work/task/test +29 -0
  118. data/work/test/ets_runner.rb +33 -0
  119. data/work/test/libxml_test.rb +3 -0
  120. data/work/test/runner.rb +0 -0
  121. data/work/test/runner_ets.rb +33 -0
  122. data/work/vc/debug/libxml.exp +0 -0
  123. data/work/vc/debug/libxml.ilk +0 -0
  124. data/work/vc/debug/libxml.lib +0 -0
  125. data/work/vc/debug/libxml.pdb +0 -0
  126. data/work/vc/debug/libxml.so +0 -0
  127. metadata +224 -0
@@ -0,0 +1,56 @@
1
+ /* $Id: ruby_xml_sax_parser.h 111 2006-11-20 01:39:14Z roscopeco $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_SAX_PARSER__
6
+ #define __RUBY_XML_SAX_PARSER__
7
+
8
+ extern VALUE cXMLSaxParser;
9
+ extern VALUE mXMLSaxParserCallbacks;
10
+
11
+ /*
12
+ typedef struct ruby_xml_sax_parser_callbacks {
13
+ VALUE internalSubset;
14
+ VALUE isStandalone;
15
+ VALUE hasInternalSubset;
16
+ VALUE hasExternalSubset;
17
+ VALUE resolveEntity;
18
+ VALUE getEntity;
19
+ VALUE entityDecl;
20
+ VALUE notationDecl;
21
+ VALUE attributeDecl;
22
+ VALUE elementDecl;
23
+ VALUE unparsedEntityDecl;
24
+ VALUE setDocumentLocator;
25
+ VALUE startDocument;
26
+ VALUE endDocument;
27
+ VALUE startElement;
28
+ VALUE endElement;
29
+ VALUE reference;
30
+ VALUE characters;
31
+ VALUE ignorableWhitespace;
32
+ VALUE processingInstruction;
33
+ VALUE comment;
34
+ VALUE xmlParserWarning;
35
+ VALUE xmlParserError;
36
+ VALUE xmlParserFatalError;
37
+ VALUE getParameterEntity;
38
+ VALUE cdataBlock;
39
+ VALUE externalSubset;
40
+ } ruby_xml_sax_parser_callbacks;
41
+ */
42
+
43
+ typedef struct ruby_xml_sax_parser {
44
+ xmlParserCtxtPtr xpc;
45
+ xmlSAXHandlerPtr xsh;
46
+ //ruby_xml_sax_parser_callbacks *cbp;
47
+ VALUE callbackHandler;
48
+ VALUE filename;
49
+ VALUE str;
50
+ } ruby_xml_sax_parser;
51
+
52
+ void ruby_xml_sax_parser_free(ruby_xml_sax_parser *rxsp);
53
+ void ruby_init_xml_sax_parser(void);
54
+ VALUE ruby_xml_sax_parser_new(VALUE class);
55
+
56
+ #endif
@@ -0,0 +1,146 @@
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml_schema.h"
3
+
4
+ VALUE cXMLSchema;
5
+
6
+ static void
7
+ ruby_xml_schema_mark(ruby_xml_schema *rxschema) {
8
+ return;
9
+ }
10
+
11
+ void
12
+ ruby_xml_schema_free(ruby_xml_schema *rxschema) {
13
+ if (rxschema->schema != NULL) {
14
+ xmlSchemaFree(rxschema->schema);
15
+ rxschema->schema = NULL;
16
+ }
17
+
18
+ ruby_xfree(rxschema);
19
+ }
20
+
21
+ /*
22
+ * call-seq:
23
+ * XML::Schema.new(schema_uri) => schema
24
+ *
25
+ * Create a new schema from the specified URI.
26
+ */
27
+ VALUE
28
+ ruby_xml_schema_init_from_uri(int argc, VALUE *argv, VALUE class) {
29
+ xmlSchemaParserCtxtPtr parser;
30
+ ruby_xml_schema *schema;
31
+
32
+ VALUE uri;
33
+ VALUE result = Qnil;
34
+
35
+ switch (argc) {
36
+ case 1:
37
+ rb_scan_args(argc, argv, "10", &uri);
38
+ Check_Type(uri, T_STRING);
39
+
40
+ parser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
41
+ schema = ALLOC(ruby_xml_schema);
42
+ schema->schema = xmlSchemaParse(parser);
43
+ xmlSchemaFreeParserCtxt(parser);
44
+
45
+ result = Data_Wrap_Struct(cXMLSchema, ruby_xml_schema_mark, ruby_xml_schema_free, schema);
46
+ break;
47
+ default:
48
+ rb_raise(rb_eArgError, "wrong number of arguments (need 1)");
49
+ }
50
+ return(result);
51
+ }
52
+
53
+ /*
54
+ * call-seq:
55
+ * XML::Schema.from_string("schema_data") => "value"
56
+ *
57
+ * Create a new schema using the specified string.
58
+ */
59
+ VALUE
60
+ ruby_xml_schema_init_from_str(int argc, VALUE *argv, VALUE class) {
61
+ VALUE schema_str;
62
+
63
+ xmlSchemaParserCtxtPtr parser;
64
+ //xmlSchemaPtr sptr;
65
+ ruby_xml_schema *rxschema;
66
+
67
+ switch (argc) {
68
+ case 1:
69
+ rb_scan_args(argc, argv, "10", &schema_str);
70
+
71
+ Check_Type(schema_str, T_STRING);
72
+
73
+ parser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(StringValuePtr(schema_str)));
74
+ rxschema = ALLOC(ruby_xml_schema);
75
+ rxschema->schema = xmlSchemaParse(parser);
76
+ xmlSchemaFreeParserCtxt(parser);
77
+
78
+ return( Data_Wrap_Struct(cXMLSchema, ruby_xml_schema_mark, ruby_xml_schema_free, rxschema) );
79
+ default:
80
+ rb_raise(rb_eArgError, "wrong number of arguments (need 1)");
81
+ }
82
+ return Qnil;
83
+ }
84
+
85
+ /* TODO what is this patch doing here?
86
+
87
+ xmlSchemaParserCtxtPtr parser;
88
+ xmlSchemaPtr sptr;
89
+ xmlSchemaValidCtxtPtr vptr;
90
+ + int is_invalid;
91
+
92
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &source) == FAILURE) {
93
+ return;
94
+ @@ -598,26 +598,24 @@
95
+ convert_to_string_ex(&source);
96
+ parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source));
97
+ sptr = xmlSchemaParse(parser);
98
+ break;
99
+ case SCHEMA_BLOB:
100
+ convert_to_string_ex(&source);
101
+ parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source), Z_STRLEN_P(source));
102
+ sptr = xmlSchemaParse(parser);
103
+ break;
104
+ }
105
+
106
+ vptr = xmlSchemaNewValidCtxt(sptr);
107
+ + is_invalid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
108
+ xmlSchemaFree(sptr);
109
+ xmlSchemaFreeValidCtxt(vptr);
110
+ xmlSchemaFreeParserCtxt(parser);
111
+
112
+ - if (is_valid) {
113
+ - RETURN_TRUE;
114
+ - } else {
115
+ + if (is_invalid) {
116
+ RETURN_FALSE;
117
+ + } else {
118
+ + RETURN_TRUE;
119
+ }
120
+ }
121
+ }}}
122
+ @@ -695,7 +693,7 @@
123
+ {
124
+ if (!strcmp(method, "xsearch")) {
125
+ simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU);
126
+ -#ifdef xmlSchemaParserCtxtPtr
127
+ +#ifdef LIBXML_SCHEMAS_ENABLED
128
+ } else if (!strcmp(method, "validate_schema_file")) {
129
+ simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_FILE);
130
+ } else if (!strcmp(method, "validate_schema_buffer")) {
131
+ */
132
+
133
+ void ruby_schema_free(ruby_xml_schema *rxs) {
134
+ }
135
+
136
+ // Rdoc needs to know
137
+ #ifdef RDOC_NEVER_DEFINED
138
+ mXML = rb_define_module("XML");
139
+ #endif
140
+
141
+ void ruby_init_xml_schema(void) {
142
+ cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
143
+ rb_define_singleton_method(cXMLSchema, "new", ruby_xml_schema_init_from_uri, -1);
144
+ rb_define_singleton_method(cXMLSchema, "from_string", ruby_xml_schema_init_from_str, -1);
145
+ }
146
+
@@ -0,0 +1,16 @@
1
+ #ifndef __RUBY_XML_SCHEMA__
2
+ #define __RUBY_XML_SCHEMA__
3
+
4
+ #include <libxml/schemasInternals.h>
5
+ #include <libxml/xmlschemas.h>
6
+
7
+ extern VALUE cXMLSchema;
8
+
9
+ typedef struct rxp_schema {
10
+ xmlSchemaPtr schema; /* Schema interface */
11
+ } ruby_xml_schema;
12
+
13
+ void ruby_init_xml_schema(void);
14
+ void ruby_schema_free(ruby_xml_schema *rxs);
15
+ #endif
16
+
@@ -0,0 +1,113 @@
1
+ /* $Id$ */
2
+
3
+ #include "ruby_libxml.h"
4
+
5
+ VALUE cXMLState;
6
+ static VALUE weak_holder;
7
+ static int id_inst;
8
+
9
+ ID id_state;
10
+
11
+ #undef DEBUG
12
+
13
+ void
14
+ ruby_xml_state_free(int * dummy) {
15
+ if ( dummy==NULL ) return;
16
+ xmlCleanupParser();
17
+ ruby_xfree(dummy);
18
+ dummy=NULL;
19
+ weak_holder=Qnil;
20
+ rb_ivar_set(cXMLState,id_state,Qnil);
21
+ }
22
+
23
+ void
24
+ ruby_xml_state_mark(void * a) {
25
+ #ifdef DEBUG
26
+ fprintf(stderr,"marked 0x%x\n",NUM2INT(rb_ivar_get(cXMLState,id_state)));
27
+ #endif
28
+ }
29
+
30
+ VALUE
31
+ ruby_xml_state_object() {
32
+ VALUE obj,id;
33
+ int *dummy;
34
+
35
+ id=rb_ivar_get(cXMLState,id_state);
36
+ if (NIL_P(id)) {
37
+ obj = Data_Make_Struct(cXMLState, int,
38
+ ruby_xml_state_mark,
39
+ ruby_xml_state_free,
40
+ dummy);
41
+ rb_ivar_set(cXMLState,id_state,id=rb_obj_id(obj));
42
+ *dummy=0;
43
+ weak_holder=obj;
44
+ return obj;
45
+ }
46
+
47
+ #ifdef DEBUG
48
+ fprintf(stderr,"getting 0x%x\n",NUM2INT(id));
49
+ #endif
50
+ return weak_holder;
51
+
52
+ return rb_funcall(rb_const_get(rb_cModule,rb_intern("ObjectSpace")),
53
+ rb_intern("_id2ref"),
54
+ 1,
55
+ id);
56
+ }
57
+
58
+ VALUE
59
+ ruby_xml_state_object_find_aux(VALUE id) {
60
+ return rb_funcall(rb_const_get(rb_cModule,rb_intern("ObjectSpace")),
61
+ rb_intern("_id2ref"),
62
+ 1, id);
63
+ }
64
+
65
+
66
+ static VALUE
67
+ find_failed() {
68
+ return Qnil;
69
+ }
70
+
71
+ VALUE
72
+ ruby_xml_state_object_find(VALUE id) {
73
+ return rb_rescue(ruby_xml_state_object_find_aux, id, find_failed, 0);
74
+ }
75
+ /*
76
+ * This will establish a use and mark it or mark an existing use.
77
+ * should be called by parser.mark and document.mark
78
+ */
79
+ void
80
+ ruby_xml_state_marker(void) {
81
+ ruby_xml_state_object();
82
+ rb_gc_mark(weak_holder);
83
+ }
84
+
85
+ VALUE
86
+ ruby_xml_state_used_p(VALUE klass)
87
+ {
88
+ return rb_ivar_get(cXMLState,id_state);
89
+ }
90
+
91
+ VALUE
92
+ ruby_xml_state_use(VALUE klass)
93
+ {
94
+ return ruby_xml_state_object();
95
+ }
96
+
97
+ // Rdoc needs to know
98
+ #ifdef RDOC_NEVER_DEFINED
99
+ mXML = rb_define_module("XML");
100
+ #endif
101
+
102
+
103
+ void
104
+ ruby_init_state(void) {
105
+ cXMLState = rb_define_class_under(mXML, "State", rb_cObject);
106
+
107
+ rb_define_singleton_method(cXMLState, "used?",
108
+ ruby_xml_state_used_p, 0);
109
+ rb_define_singleton_method(cXMLState, "use",
110
+ ruby_xml_state_use, 0);
111
+
112
+ rb_ivar_set(cXMLState, id_state=rb_intern("@stateid"), Qnil);
113
+ }
@@ -0,0 +1,12 @@
1
+ /* $Id$ */
2
+
3
+ #ifndef __RUBY_XML_STATE__
4
+ #define __RUBY_XML_STATE__
5
+
6
+ extern VALUE cXMLState;
7
+
8
+ void ruby_init_state(void);
9
+ void ruby_xml_state_marker(void);
10
+ VALUE ruby_xml_state_object_find(VALUE id);
11
+
12
+ #endif
@@ -0,0 +1,43 @@
1
+ /* $Id: ruby_xml_tree.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_tree.h"
7
+
8
+ VALUE cXMLTree;
9
+
10
+ // Rdoc needs to know
11
+ #ifdef RDOC_NEVER_DEFINED
12
+ mXML = rb_define_module("XML");
13
+ #endif
14
+
15
+ void
16
+ ruby_init_xml_tree(void) {
17
+ cXMLTree = rb_define_class_under(mXML, "Tree", rb_cObject);
18
+
19
+ rb_define_const(cXMLTree, "ELEMENT_NODE", INT2FIX(XML_ELEMENT_NODE));
20
+ rb_define_const(cXMLTree, "ATTRIBUTE_NODE", INT2FIX(XML_ATTRIBUTE_NODE));
21
+ rb_define_const(cXMLTree, "TEXT_NODE", INT2FIX(XML_TEXT_NODE));
22
+ rb_define_const(cXMLTree, "CDATA_SECTION_NODE", INT2FIX(XML_CDATA_SECTION_NODE));
23
+ rb_define_const(cXMLTree, "ENTITY_REF_NODE", INT2FIX(XML_ENTITY_REF_NODE));
24
+ rb_define_const(cXMLTree, "ENTITY_NODE", INT2FIX(XML_ENTITY_NODE));
25
+ rb_define_const(cXMLTree, "PI_NODE", INT2FIX(XML_PI_NODE));
26
+ rb_define_const(cXMLTree, "COMMENT_NODE", INT2FIX(XML_COMMENT_NODE));
27
+ rb_define_const(cXMLTree, "DOCUMENT_NODE", INT2FIX(XML_DOCUMENT_NODE));
28
+ rb_define_const(cXMLTree, "DOCUMENT_TYPE_NODE", INT2FIX(XML_DOCUMENT_TYPE_NODE));
29
+ rb_define_const(cXMLTree, "DOCUMENT_FRAG_NODE", INT2FIX(XML_DOCUMENT_FRAG_NODE));
30
+ rb_define_const(cXMLTree, "NOTATION_NODE", INT2FIX(XML_NOTATION_NODE));
31
+ rb_define_const(cXMLTree, "HTML_DOCUMENT_NODE", INT2FIX(XML_HTML_DOCUMENT_NODE));
32
+ rb_define_const(cXMLTree, "DTD_NODE", INT2FIX(XML_DTD_NODE));
33
+ rb_define_const(cXMLTree, "ELEMENT_DECL", INT2FIX(XML_ELEMENT_DECL));
34
+ rb_define_const(cXMLTree, "ATTRIBUTE_DECL", INT2FIX(XML_ATTRIBUTE_DECL));
35
+ rb_define_const(cXMLTree, "ENTITY_DECL", INT2FIX(XML_ENTITY_DECL));
36
+ rb_define_const(cXMLTree, "NAMESPACE_DECL", INT2FIX(XML_NAMESPACE_DECL));
37
+ rb_define_const(cXMLTree, "XINCLUDE_START", INT2FIX(XML_XINCLUDE_START));
38
+ rb_define_const(cXMLTree, "XINCLUDE_END", INT2FIX(XML_XINCLUDE_END));
39
+
40
+ #ifdef LIBXML_DOCB_ENABLED
41
+ rb_define_const(cXMLTree, "DOCB_DOCUMENT_NODE", INT2FIX(XML_DOCB_DOCUMENT_NODE));
42
+ #endif
43
+ }
@@ -0,0 +1,12 @@
1
+ /* $Id: ruby_xml_tree.h 39 2006-02-21 20:40:16Z roscopeco $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_TREE__
6
+ #define __RUBY_XML_TREE__
7
+
8
+ extern VALUE cXMLTree;
9
+
10
+ void ruby_init_xml_tree(void);
11
+
12
+ #endif
@@ -0,0 +1,20 @@
1
+ /* $Id: ruby_xml_xinclude.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_xinclude.h"
7
+
8
+ VALUE cXMLXInclude;
9
+ VALUE eXMLXIncludeError;
10
+
11
+ // Rdoc needs to know
12
+ #ifdef RDOC_NEVER_DEFINED
13
+ mXML = rb_define_module("XML");
14
+ #endif
15
+
16
+ void
17
+ ruby_init_xml_xinclude(void) {
18
+ cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
19
+ eXMLXIncludeError = rb_define_class_under(cXMLXInclude, "Error", rb_eRuntimeError);
20
+ }
@@ -0,0 +1,13 @@
1
+ /* $Id: ruby_xml_xinclude.h 39 2006-02-21 20:40:16Z roscopeco $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_XINCLUDE__
6
+ #define __RUBY_XML_XINCLUDE__
7
+
8
+ extern VALUE cXMLXInclude;
9
+ extern VALUE eXMLXIncludeError;
10
+
11
+ void ruby_init_xml_xinclude(void);
12
+
13
+ #endif
@@ -0,0 +1,243 @@
1
+ /* $Id: ruby_xml_xpath.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_xpath.h"
7
+
8
+ /*
9
+ * Document-class: XML::XPath
10
+ *
11
+ * Includes Enumerable.
12
+ */
13
+ VALUE cXMLXPath;
14
+ VALUE eXMLXPathInvalidPath;
15
+
16
+ #ifdef LIBXML_XPATH_ENABLED
17
+
18
+ /*
19
+ * call-seq:
20
+ * xpath.debug => (true|false)
21
+ *
22
+ * Dump libxml debugging information to stdout.
23
+ * Requires Libxml be compiled with debugging enabled.
24
+ */
25
+ VALUE
26
+ ruby_xml_xpath_debug(VALUE self) {
27
+ #ifdef LIBXML_DEBUG_ENABLED
28
+ ruby_xml_xpath *rxxp;
29
+ Data_Get_Struct(self, ruby_xml_xpath, rxxp);
30
+
31
+ if (rxxp->xpop != NULL) {
32
+ xmlXPathDebugDumpObject(stdout, rxxp->xpop, 0);
33
+ return(Qtrue);
34
+ } else {
35
+ return(Qfalse);
36
+ }
37
+ #else
38
+ rb_warn("libxml does not have debugging turned on");
39
+ return(Qfalse);
40
+ #endif
41
+ }
42
+
43
+ ///////////////////////////////////////////////////
44
+ // TODO xpath_find is throwing TypeError:
45
+ //
46
+ // TypeError: can't convert nil into String
47
+ //
48
+ // When given a namespace when non exist.
49
+ void
50
+ ruby_xml_xpath_register_namespaces(VALUE nslist, VALUE xxpc, int level) {
51
+ char *cp;
52
+ long i;
53
+ VALUE rprefix, ruri;
54
+ ruby_xml_ns *rxns;
55
+
56
+ /* Need to loop through the 2nd argument and iterate through the
57
+ * list of namespaces that we want to allow */
58
+ switch (TYPE(nslist)) {
59
+ case T_STRING:
60
+ cp = strchr(StringValuePtr(nslist), (int)':');
61
+ if (cp == NULL) {
62
+ rprefix = nslist;
63
+ ruri = Qnil;
64
+ } else {
65
+ rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
66
+ ruri = rb_str_new2(&cp[1]);
67
+ }
68
+ /* Should test the results of this */
69
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
70
+ break;
71
+ case T_ARRAY:
72
+ if ( level == 0 ) {
73
+ for (i = 0; i < RARRAY(nslist)->len; i++) {
74
+ ruby_xml_xpath_register_namespaces(RARRAY(nslist)->ptr[i],xxpc,1);
75
+ }
76
+ }
77
+ else {
78
+ // tuples of prefix/uri
79
+ if (RARRAY(nslist)->len == 2) {
80
+ rprefix = RARRAY(nslist)->ptr[0];
81
+ ruri = RARRAY(nslist)->ptr[1];
82
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
83
+ } else {
84
+ rb_raise(rb_eArgError, "nested array must be an array of strings, prefix and href/uri");
85
+ }
86
+ }
87
+ break;
88
+ default:
89
+ if (rb_obj_is_kind_of(nslist, cXMLNS) == Qtrue) {
90
+ Data_Get_Struct(nslist, ruby_xml_ns, rxns);
91
+ rprefix = rb_str_new2((const char*)rxns->ns->prefix);
92
+ ruri = rb_str_new2((const char*)rxns->ns->href);
93
+ ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
94
+ } else
95
+ rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
96
+ }
97
+ }
98
+ /*
99
+ * call-seq:
100
+ * XML::XPath.find(path, namespaces = [any]) => xpath
101
+ *
102
+ * Find nodes matching the specified xpath (and optionally any of the
103
+ * supplied namespaces) and return as an XML::Node::Set.
104
+ *
105
+ * The optional namespaces argument may take one of
106
+ * two forms:
107
+ *
108
+ * * A string in the form of: "prefix:uri", or
109
+ * * An array of:
110
+ * * strings in the form like above
111
+ * * arrays in the form of ['prefix','uri']
112
+ *
113
+ * If not specified, matching nodes from any namespace
114
+ * will be included.
115
+ */
116
+ VALUE
117
+ ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist) {
118
+ #ifdef LIBXML_XPATH_ENABLED
119
+ xmlXPathCompExprPtr comp;
120
+ xmlXPathObjectPtr xxpop;
121
+ ruby_xml_node *node;
122
+ xmlXPathContextPtr ctxt;
123
+ ruby_xml_document_t *rdocp;
124
+ VALUE rnode, xxpc;
125
+ VALUE rxpop;
126
+
127
+ if (rb_obj_is_kind_of(anode, cXMLDocument) == Qtrue) {
128
+ xxpc = ruby_xml_xpath_context_new(anode);
129
+ Data_Get_Struct(anode, ruby_xml_document_t, rdocp);
130
+ #ifdef DEBUG
131
+ fprintf(stderr,"rdocp=0x%x root=0x%x\n",rdocp,xmlDocGetRootElement(rdocp->doc));
132
+ #endif
133
+ rnode=ruby_xml_node2_wrap(cXMLNode,xmlDocGetRootElement(rdocp->doc));
134
+ #ifdef DEBUG
135
+ fprintf(stderr,"rnode 0x%x 0x%x\n",rnode,xmlDocGetRootElement(rdocp->doc)->_private);
136
+ #endif
137
+ Data_Get_Struct(rnode, ruby_xml_node, node);
138
+ } else if ( rb_obj_is_kind_of(anode, cXMLNode) == Qtrue) {
139
+ xxpc = ruby_xml_xpath_context_new(anode);
140
+ Data_Get_Struct(anode, ruby_xml_node, node);
141
+ } else
142
+ rb_raise(rb_eTypeError, "arg 1 must be XML::Document or XML::Node within a document %s", rb_obj_as_string(anode));
143
+
144
+ if (NIL_P(xxpc))
145
+ return(Qnil);
146
+
147
+ Data_Get_Struct(xxpc,xmlXPathContext,ctxt);
148
+ // XXX Is this legal? Set a subtree to apply xpath?
149
+ ctxt->node = node->node;
150
+
151
+ // XXX is setting ->namespaces used?
152
+ if (node->node->type == XML_DOCUMENT_NODE) {
153
+ ctxt->namespaces = xmlGetNsList(node->node->doc,
154
+ xmlDocGetRootElement(node->node->doc));
155
+ } else {
156
+ ctxt->namespaces = xmlGetNsList(node->node->doc, node->node);
157
+ }
158
+
159
+ ctxt->nsNr = 0;
160
+ if (ctxt->namespaces != NULL) {
161
+ while (ctxt->namespaces[ctxt->nsNr] != NULL)
162
+ ctxt->nsNr++;
163
+ }
164
+
165
+ if ( ! NIL_P(nslist) )
166
+ ruby_xml_xpath_register_namespaces(nslist,xxpc,0);
167
+
168
+ comp = xmlXPathCompile((xmlChar*)StringValuePtr(xpath_expr));
169
+
170
+ if (comp == NULL) {
171
+ rb_raise(eXMLXPathInvalidPath,
172
+ "Invalid XPath expression (expr does not compile)");
173
+ }
174
+ xxpop=xmlXPathCompiledEval(comp, ctxt);
175
+ if ( xxpop == NULL )
176
+ return Qnil;
177
+
178
+ rxpop = ruby_xml_xpath_object_wrap(xxpop);
179
+
180
+ #ifdef NODE_DEBUG
181
+ fprintf(stderr,"xpo 0x%x class=%s\n",
182
+ rxpop,
183
+ rb_class2name(rb_obj_class(rxpop)));
184
+ #endif
185
+
186
+ xmlXPathFreeCompExpr(comp);
187
+
188
+ if (rxpop == Qnil)
189
+ rb_raise(eXMLXPathInvalidPath,
190
+ "Invalid XPath expression for this document");
191
+
192
+ return rxpop;
193
+ #else
194
+ rb_warn("libxml was compiled without XPath support");
195
+ return(Qfalse);
196
+ #endif
197
+ }
198
+
199
+
200
+ VALUE
201
+ ruby_xml_xpath_findva(int argc, VALUE *argv, VALUE class) {
202
+ if ( argc < 2 || argc > 3 )
203
+ rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
204
+
205
+ return ruby_xml_xpath_find(class,argv[0],argv[1],(argc==3)?argv[2]:Qnil);
206
+ }
207
+
208
+ VALUE
209
+ ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist) {
210
+ return ruby_xml_xpath_find(cXMLXPath, anode, xpath_expr, nslist);
211
+ }
212
+
213
+ // Rdoc needs to know
214
+ #ifdef RDOC_NEVER_DEFINED
215
+ mXML = rb_define_module("XML");
216
+ #endif
217
+
218
+ void
219
+ ruby_init_xml_xpath(void) {
220
+ cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
221
+ rb_include_module(cXMLNode, rb_const_get(rb_cObject, rb_intern("Enumerable")));
222
+
223
+ eXMLXPathInvalidPath = rb_define_class_under(cXMLXPath, "InvalidPath", eXMLError);
224
+
225
+ rb_define_const(cXMLXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
226
+ rb_define_const(cXMLXPath, "NODESET", INT2NUM(XPATH_NODESET));
227
+ rb_define_const(cXMLXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
228
+ rb_define_const(cXMLXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
229
+ rb_define_const(cXMLXPath, "STRING", INT2NUM(XPATH_STRING));
230
+ rb_define_const(cXMLXPath, "POINT", INT2NUM(XPATH_POINT));
231
+ rb_define_const(cXMLXPath, "RANGE", INT2NUM(XPATH_RANGE));
232
+ rb_define_const(cXMLXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
233
+ rb_define_const(cXMLXPath, "USERS", INT2NUM(XPATH_USERS));
234
+ rb_define_const(cXMLXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
235
+
236
+ rb_define_singleton_method(cXMLXPath, "find", ruby_xml_xpath_findva, -1);
237
+
238
+ rb_define_method(cXMLXPath, "debug", ruby_xml_xpath_debug, 0);
239
+
240
+ ruby_init_xml_xpath_object();
241
+ }
242
+
243
+ #endif /* ifdef LIBXML_XPATH_ENABLED */