coupa-libxml-ruby 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. data/CHANGES +488 -0
  2. data/LICENSE +22 -0
  3. data/README +161 -0
  4. data/Rakefile +188 -0
  5. data/doc/css/normal.css +182 -0
  6. data/doc/img/raze-tiny.png +0 -0
  7. data/doc/img/red-cube.jpg +0 -0
  8. data/doc/img/xml-ruby.png +0 -0
  9. data/doc/index.xml +43 -0
  10. data/doc/install.xml +77 -0
  11. data/doc/layout.rhtml +38 -0
  12. data/doc/layout.xsl +67 -0
  13. data/doc/license.xml +32 -0
  14. data/doc/log/changelog.xml +1324 -0
  15. data/doc/log/changelog.xsl +42 -0
  16. data/doc/rdoc/classes/LibXML.html +207 -0
  17. data/doc/rdoc/classes/LibXML/XML.html +407 -0
  18. data/doc/rdoc/classes/LibXML/XML/Attr.html +521 -0
  19. data/doc/rdoc/classes/LibXML/XML/AttrDecl.html +360 -0
  20. data/doc/rdoc/classes/LibXML/XML/Attributes.html +149 -0
  21. data/doc/rdoc/classes/LibXML/XML/Document.html +460 -0
  22. data/doc/rdoc/classes/LibXML/XML/Error.html +129 -0
  23. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +263 -0
  24. data/doc/rdoc/classes/LibXML/XML/Namespace.html +248 -0
  25. data/doc/rdoc/classes/LibXML/XML/Namespaces.html +200 -0
  26. data/doc/rdoc/classes/LibXML/XML/Node.html +1351 -0
  27. data/doc/rdoc/classes/LibXML/XML/Parser.html +328 -0
  28. data/doc/rdoc/classes/LibXML/XML/Reader.html +172 -0
  29. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +232 -0
  30. data/doc/rdoc/classes/LibXML/XML/SaxParser/Callbacks.html +506 -0
  31. data/doc/rdoc/classes/LibXML/XML/SaxParser/VerboseCallbacks.html +555 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath.html +111 -0
  33. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +162 -0
  34. data/doc/rdoc/classes/cXMLDtd.html +114 -0
  35. data/doc/rdoc/classes/cXMLNode.html +114 -0
  36. data/doc/rdoc/created.rid +1 -0
  37. data/doc/rdoc/files/CHANGES.html +794 -0
  38. data/doc/rdoc/files/LICENSE.html +131 -0
  39. data/doc/rdoc/files/README.html +343 -0
  40. data/doc/rdoc/files/ext/libxml/libxml_c.html +101 -0
  41. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +101 -0
  42. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_decl_c.html +101 -0
  43. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +101 -0
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_c.html +101 -0
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_cbg_c.html +101 -0
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +101 -0
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +101 -0
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_encoding_c.html +101 -0
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_error_c.html +101 -0
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +101 -0
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_context_c.html +101 -0
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_options_c.html +101 -0
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +101 -0
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_io_c.html +101 -0
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_namespace_c.html +101 -0
  56. data/doc/rdoc/files/ext/libxml/ruby_xml_namespaces_c.html +101 -0
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +101 -0
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +101 -0
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +101 -0
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_options_c.html +101 -0
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +101 -0
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +101 -0
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_sax2_handler_c.html +101 -0
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +101 -0
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +101 -0
  66. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +101 -0
  67. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +101 -0
  68. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +101 -0
  69. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_expression_c.html +101 -0
  70. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +101 -0
  71. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +101 -0
  72. data/doc/rdoc/files/lib/libxml/attr_decl_rb.html +101 -0
  73. data/doc/rdoc/files/lib/libxml/attr_rb.html +101 -0
  74. data/doc/rdoc/files/lib/libxml/attributes_rb.html +101 -0
  75. data/doc/rdoc/files/lib/libxml/document_rb.html +101 -0
  76. data/doc/rdoc/files/lib/libxml/error_rb.html +101 -0
  77. data/doc/rdoc/files/lib/libxml/hpricot_rb.html +192 -0
  78. data/doc/rdoc/files/lib/libxml/html_parser_rb.html +101 -0
  79. data/doc/rdoc/files/lib/libxml/namespace_rb.html +101 -0
  80. data/doc/rdoc/files/lib/libxml/namespaces_rb.html +101 -0
  81. data/doc/rdoc/files/lib/libxml/node_rb.html +108 -0
  82. data/doc/rdoc/files/lib/libxml/ns_rb.html +101 -0
  83. data/doc/rdoc/files/lib/libxml/parser_rb.html +101 -0
  84. data/doc/rdoc/files/lib/libxml/properties_rb.html +101 -0
  85. data/doc/rdoc/files/lib/libxml/reader_rb.html +101 -0
  86. data/doc/rdoc/files/lib/libxml/sax_callbacks_rb.html +101 -0
  87. data/doc/rdoc/files/lib/libxml/sax_parser_rb.html +101 -0
  88. data/doc/rdoc/files/lib/libxml/tree_rb.html +101 -0
  89. data/doc/rdoc/files/lib/libxml/xpath_object_rb.html +101 -0
  90. data/doc/rdoc/files/lib/libxml_rb.html +133 -0
  91. data/doc/rdoc/files/lib/xml/libxml_rb.html +124 -0
  92. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  93. data/doc/rdoc/fr_class_index.html +46 -0
  94. data/doc/rdoc/fr_file_index.html +84 -0
  95. data/doc/rdoc/fr_method_index.html +155 -0
  96. data/doc/rdoc/index.html +24 -0
  97. data/doc/rdoc/rdoc-style.css +208 -0
  98. data/ext/libxml/Makefile +157 -0
  99. data/ext/libxml/build.log +4 -0
  100. data/ext/libxml/extconf.h +5 -0
  101. data/ext/libxml/extconf.rb +278 -0
  102. data/ext/libxml/libxml.c +77 -0
  103. data/ext/libxml/libxml.o +0 -0
  104. data/ext/libxml/libxml_ruby.bundle +0 -0
  105. data/ext/libxml/mkmf.log +228 -0
  106. data/ext/libxml/ruby_libxml.h +93 -0
  107. data/ext/libxml/ruby_xml.c +893 -0
  108. data/ext/libxml/ruby_xml.h +10 -0
  109. data/ext/libxml/ruby_xml.o +0 -0
  110. data/ext/libxml/ruby_xml_attr.c +352 -0
  111. data/ext/libxml/ruby_xml_attr.h +14 -0
  112. data/ext/libxml/ruby_xml_attr.o +0 -0
  113. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  114. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  115. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  116. data/ext/libxml/ruby_xml_attributes.c +277 -0
  117. data/ext/libxml/ruby_xml_attributes.h +17 -0
  118. data/ext/libxml/ruby_xml_attributes.o +0 -0
  119. data/ext/libxml/ruby_xml_cbg.c +86 -0
  120. data/ext/libxml/ruby_xml_cbg.o +0 -0
  121. data/ext/libxml/ruby_xml_document.c +1006 -0
  122. data/ext/libxml/ruby_xml_document.c.old +936 -0
  123. data/ext/libxml/ruby_xml_document.h +17 -0
  124. data/ext/libxml/ruby_xml_document.o +0 -0
  125. data/ext/libxml/ruby_xml_dtd.c +257 -0
  126. data/ext/libxml/ruby_xml_dtd.h +9 -0
  127. data/ext/libxml/ruby_xml_dtd.o +0 -0
  128. data/ext/libxml/ruby_xml_encoding.c +134 -0
  129. data/ext/libxml/ruby_xml_encoding.h +12 -0
  130. data/ext/libxml/ruby_xml_encoding.o +0 -0
  131. data/ext/libxml/ruby_xml_error.c +1004 -0
  132. data/ext/libxml/ruby_xml_error.h +14 -0
  133. data/ext/libxml/ruby_xml_error.o +0 -0
  134. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  135. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  136. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  137. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  138. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  139. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  140. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  141. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  142. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  143. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  144. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  145. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  146. data/ext/libxml/ruby_xml_io.c +30 -0
  147. data/ext/libxml/ruby_xml_io.h +9 -0
  148. data/ext/libxml/ruby_xml_io.o +0 -0
  149. data/ext/libxml/ruby_xml_namespace.c +170 -0
  150. data/ext/libxml/ruby_xml_namespace.h +12 -0
  151. data/ext/libxml/ruby_xml_namespace.o +0 -0
  152. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  153. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  154. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  155. data/ext/libxml/ruby_xml_node.c +1386 -0
  156. data/ext/libxml/ruby_xml_node.h +13 -0
  157. data/ext/libxml/ruby_xml_node.o +0 -0
  158. data/ext/libxml/ruby_xml_parser.c +94 -0
  159. data/ext/libxml/ruby_xml_parser.h +14 -0
  160. data/ext/libxml/ruby_xml_parser.o +0 -0
  161. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  162. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  163. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  164. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  165. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  166. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  167. data/ext/libxml/ruby_xml_reader.c +1002 -0
  168. data/ext/libxml/ruby_xml_reader.h +14 -0
  169. data/ext/libxml/ruby_xml_reader.o +0 -0
  170. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  171. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  172. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  173. data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
  174. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  175. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  176. data/ext/libxml/ruby_xml_sax_parser.c +137 -0
  177. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  178. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  179. data/ext/libxml/ruby_xml_schema.c +159 -0
  180. data/ext/libxml/ruby_xml_schema.h +11 -0
  181. data/ext/libxml/ruby_xml_schema.o +0 -0
  182. data/ext/libxml/ruby_xml_version.h +9 -0
  183. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  184. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  185. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  186. data/ext/libxml/ruby_xml_xpath.c +107 -0
  187. data/ext/libxml/ruby_xml_xpath.h +12 -0
  188. data/ext/libxml/ruby_xml_xpath.o +0 -0
  189. data/ext/libxml/ruby_xml_xpath_context.c +387 -0
  190. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  191. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  192. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  193. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  194. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  195. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  196. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  197. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  198. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  199. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  200. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  201. data/ext/mingw/Rakefile +34 -0
  202. data/ext/mingw/build.rake +41 -0
  203. data/ext/vc/libxml_ruby.sln +26 -0
  204. data/lib/libxml.rb +30 -0
  205. data/lib/libxml/attr.rb +111 -0
  206. data/lib/libxml/attr_decl.rb +78 -0
  207. data/lib/libxml/attributes.rb +12 -0
  208. data/lib/libxml/document.rb +190 -0
  209. data/lib/libxml/error.rb +88 -0
  210. data/lib/libxml/hpricot.rb +76 -0
  211. data/lib/libxml/html_parser.rb +94 -0
  212. data/lib/libxml/namespace.rb +60 -0
  213. data/lib/libxml/namespaces.rb +36 -0
  214. data/lib/libxml/node.rb +385 -0
  215. data/lib/libxml/ns.rb +20 -0
  216. data/lib/libxml/parser.rb +365 -0
  217. data/lib/libxml/properties.rb +21 -0
  218. data/lib/libxml/reader.rb +27 -0
  219. data/lib/libxml/sax_callbacks.rb +178 -0
  220. data/lib/libxml/sax_parser.rb +56 -0
  221. data/lib/libxml/tree.rb +27 -0
  222. data/lib/libxml/xpath_object.rb +14 -0
  223. data/lib/xml.rb +14 -0
  224. data/lib/xml/libxml.rb +8 -0
  225. data/setup.rb +1585 -0
  226. data/test/etc_doc_to_s.rb +19 -0
  227. data/test/ets_doc_file.rb +15 -0
  228. data/test/ets_doc_to_s.rb +21 -0
  229. data/test/ets_gpx.rb +26 -0
  230. data/test/ets_node_gc.rb +21 -0
  231. data/test/ets_test.xml +2 -0
  232. data/test/ets_tsr.rb +9 -0
  233. data/test/model/atom.xml +13 -0
  234. data/test/model/bands.xml +5 -0
  235. data/test/model/books.xml +146 -0
  236. data/test/model/merge_bug_data.xml +58 -0
  237. data/test/model/ruby-lang.html +238 -0
  238. data/test/model/rubynet.xml +79 -0
  239. data/test/model/rubynet_project +1 -0
  240. data/test/model/shiporder.rnc +28 -0
  241. data/test/model/shiporder.rng +86 -0
  242. data/test/model/shiporder.xml +23 -0
  243. data/test/model/shiporder.xsd +31 -0
  244. data/test/model/soap.xml +27 -0
  245. data/test/model/xinclude.xml +5 -0
  246. data/test/tc_attr.rb +170 -0
  247. data/test/tc_attr_decl.rb +131 -0
  248. data/test/tc_attributes.rb +133 -0
  249. data/test/tc_deprecated_require.rb +11 -0
  250. data/test/tc_document.rb +113 -0
  251. data/test/tc_document_write.rb +118 -0
  252. data/test/tc_dtd.rb +123 -0
  253. data/test/tc_error.rb +136 -0
  254. data/test/tc_html_parser.rb +138 -0
  255. data/test/tc_namespace.rb +59 -0
  256. data/test/tc_namespaces.rb +174 -0
  257. data/test/tc_node.rb +181 -0
  258. data/test/tc_node_cdata.rb +49 -0
  259. data/test/tc_node_comment.rb +30 -0
  260. data/test/tc_node_copy.rb +40 -0
  261. data/test/tc_node_edit.rb +158 -0
  262. data/test/tc_node_text.rb +69 -0
  263. data/test/tc_node_write.rb +83 -0
  264. data/test/tc_node_xlink.rb +26 -0
  265. data/test/tc_parser.rb +330 -0
  266. data/test/tc_parser_context.rb +186 -0
  267. data/test/tc_properties.rb +36 -0
  268. data/test/tc_reader.rb +284 -0
  269. data/test/tc_relaxng.rb +51 -0
  270. data/test/tc_sax_parser.rb +274 -0
  271. data/test/tc_schema.rb +51 -0
  272. data/test/tc_traversal.rb +220 -0
  273. data/test/tc_xinclude.rb +19 -0
  274. data/test/tc_xml.rb +224 -0
  275. data/test/tc_xpath.rb +193 -0
  276. data/test/tc_xpath_context.rb +78 -0
  277. data/test/tc_xpath_expression.rb +35 -0
  278. data/test/tc_xpointer.rb +72 -0
  279. data/test/test_suite.rb +33 -0
  280. metadata +376 -0
@@ -0,0 +1,174 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestNamespaces < Test::Unit::TestCase
5
+ def setup
6
+ file = File.join(File.dirname(__FILE__), 'model/soap.xml')
7
+ @doc = XML::Document.file(file)
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def test_namespace
15
+ node = @doc.root
16
+ ns = node.namespaces.namespace
17
+ assert_equal('soap', ns.prefix)
18
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
19
+ end
20
+
21
+ def test_set_namespace
22
+ node = XML::Node.new('Envelope')
23
+ assert_equal('<Envelope/>', node.to_s)
24
+
25
+ ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
26
+ assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
27
+ assert_nil(node.namespaces.namespace)
28
+
29
+ # Now put the node in the soap namespace
30
+ node.namespaces.namespace = ns
31
+ assert_not_nil(node.namespaces.namespace)
32
+ assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
33
+ end
34
+
35
+ def test_define_namespace
36
+ node = XML::Node.new('Envelope')
37
+ assert_equal('<Envelope/>', node.to_s)
38
+
39
+ XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
40
+ assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
41
+ assert_nil(node.namespaces.namespace)
42
+ end
43
+
44
+ def test_define_default_namespace
45
+ node = XML::Node.new('Envelope')
46
+ assert_equal('<Envelope/>', node.to_s)
47
+
48
+ XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
49
+ assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
50
+ # This seems wrong, but appears to be the way libxml works
51
+ assert_nil(node.namespaces.namespace)
52
+ end
53
+
54
+ def test_namespaces
55
+ node = @doc.find_first('//ns1:IdAndName',
56
+ :ns1 => 'http://domain.somewhere.com')
57
+
58
+ namespaces = node.namespaces.sort
59
+ assert_equal(5, namespaces.length)
60
+
61
+ namespace = namespaces[0]
62
+ assert_instance_of(XML::Namespace, namespace)
63
+ assert_equal(nil, namespace.prefix)
64
+ assert_equal('http://services.somewhere.com', namespace.href)
65
+
66
+ namespace = namespaces[1]
67
+ assert_instance_of(XML::Namespace, namespace)
68
+ assert_equal('ns1', namespace.prefix)
69
+ assert_equal('http://domain.somewhere.com', namespace.href)
70
+
71
+ namespace = namespaces[2]
72
+ assert_instance_of(XML::Namespace, namespace)
73
+ assert_equal('soap', namespace.prefix)
74
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
75
+
76
+ namespace = namespaces[3]
77
+ assert_instance_of(XML::Namespace, namespace)
78
+ assert_equal('xsd', namespace.prefix)
79
+ assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
80
+
81
+ namespace = namespaces[4]
82
+ assert_instance_of(XML::Namespace, namespace)
83
+ assert_equal('xsi', namespace.prefix)
84
+ assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
85
+ end
86
+
87
+ def test_namespaces
88
+ node = @doc.find_first('//ns1:IdAndName',
89
+ :ns1 => 'http://domain.somewhere.com')
90
+
91
+ namespaces = node.namespaces.each do |namespace|
92
+ assert_instance_of(XML::Namespace, namespace)
93
+ end
94
+ end
95
+
96
+ def test_namespace_definitions
97
+ ns_defs = @doc.root.namespaces.definitions
98
+ assert_equal(3, ns_defs.size)
99
+
100
+ namespace = ns_defs[0]
101
+ assert_instance_of(XML::Namespace, namespace)
102
+ assert_equal('soap', namespace.prefix)
103
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
104
+
105
+ namespace = ns_defs[1]
106
+ assert_instance_of(XML::Namespace, namespace)
107
+ assert_equal('xsd', namespace.prefix)
108
+ assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
109
+
110
+ namespace = ns_defs[2]
111
+ assert_instance_of(XML::Namespace, namespace)
112
+ assert_equal('xsi', namespace.prefix)
113
+ assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
114
+
115
+ node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
116
+ :ns => 'http://services.somewhere.com')
117
+ ns_defs = node.namespaces.definitions
118
+ assert_equal(1, ns_defs.size)
119
+
120
+ namespace = ns_defs[0]
121
+ assert_instance_of(XML::Namespace, namespace)
122
+ assert_equal(nil, namespace.prefix)
123
+ assert_equal('http://services.somewhere.com', namespace.href)
124
+ end
125
+
126
+ def test_find_by_prefix
127
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
128
+ :ns1 => 'http://services.somewhere.com')
129
+
130
+ namespace = @doc.root.namespaces.find_by_prefix('soap')
131
+
132
+ assert_instance_of(XML::Namespace, namespace)
133
+ assert_equal('soap', namespace.prefix)
134
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
135
+ end
136
+
137
+ def test_find_default_ns
138
+ namespace = @doc.root.namespaces.find_by_prefix(nil)
139
+ assert_nil(namespace)
140
+
141
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
142
+ :ns1 => 'http://services.somewhere.com')
143
+ namespace = node.namespaces.find_by_prefix(nil)
144
+
145
+ assert_instance_of(XML::Namespace, namespace)
146
+ assert_equal(nil, namespace.prefix)
147
+ assert_equal('http://services.somewhere.com', namespace.href)
148
+ end
149
+
150
+ def test_find_ns_by_href
151
+ node = @doc.find_first('//ns1:getManufacturerNamesResponse',
152
+ :ns1 => 'http://services.somewhere.com')
153
+
154
+ namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
155
+
156
+ assert_instance_of(XML::Namespace, namespace)
157
+ assert_equal('soap', namespace.prefix)
158
+ assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
159
+ end
160
+
161
+ def test_default_namespace
162
+ doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
163
+ ns = doc.root.namespaces.default
164
+ assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
165
+ end
166
+
167
+ def test_default_prefix
168
+ doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
169
+ doc.root.namespaces.default_prefix = 'soap'
170
+
171
+ node = doc.root.find_first('/soap:Envelope')
172
+ assert_not_nil(node)
173
+ end
174
+ end
@@ -0,0 +1,181 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestNode < Test::Unit::TestCase
5
+ def setup
6
+ # Strip spaces to make testing easier
7
+ XML.default_keep_blanks = false
8
+ file = File.join(File.dirname(__FILE__), 'model/bands.xml')
9
+ @doc = XML::Document.file(file)
10
+ end
11
+
12
+ def teardown
13
+ XML.default_keep_blanks = true
14
+ @doc = nil
15
+ end
16
+
17
+ def nodes
18
+ # Find all nodes with a country attributes
19
+ @doc.find('*[@country]')
20
+ end
21
+
22
+ def test_doc_class
23
+ assert_instance_of(XML::Document, @doc)
24
+ end
25
+
26
+ def test_doc_node_type
27
+ assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
28
+ end
29
+
30
+ def test_root_class
31
+ assert_instance_of(XML::Node, @doc.root)
32
+ end
33
+
34
+ def test_root_node_type
35
+ assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
36
+ end
37
+
38
+ def test_node_class
39
+ for n in nodes
40
+ assert_instance_of(XML::Node, n)
41
+ end
42
+ end
43
+
44
+ def test_context
45
+ node = @doc.root
46
+ context = node.context
47
+ assert_instance_of(XML::XPath::Context, context)
48
+ end
49
+
50
+ def test_find
51
+ assert_instance_of(XML::XPath::Object, self.nodes)
52
+ end
53
+
54
+ def test_node_child_get
55
+ assert_instance_of(TrueClass, @doc.root.child?)
56
+ assert_instance_of(XML::Node, @doc.root.child)
57
+ assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name)
58
+ end
59
+
60
+ def test_node_doc
61
+ for n in nodes
62
+ assert_instance_of(XML::Document, n.doc) if n.document?
63
+ end
64
+ end
65
+
66
+ def test_name
67
+ assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
68
+ assert_equal("iron_maiden", nodes[1].name)
69
+ end
70
+
71
+ def test_node_find
72
+ nodes = @doc.root.find('./fixnum')
73
+ for node in nodes
74
+ assert_instance_of(XML::Node, node)
75
+ end
76
+ end
77
+
78
+ def test_equality
79
+ node_a = @doc.find_first('*[@country]')
80
+ node_b = @doc.root.child
81
+
82
+ assert(node_a == node_b)
83
+ assert(node_a.eql?(node_b))
84
+ assert(node_a.equal?(node_b))
85
+
86
+ file = File.join(File.dirname(__FILE__), 'model/bands.xml')
87
+ doc2 = XML::Document.file(file)
88
+
89
+ node_a2 = doc2.find_first('*[@country]')
90
+
91
+ assert(node_a.to_s == node_a2.to_s)
92
+ assert(node_a == node_a2)
93
+ assert(node_a.eql?(node_a2))
94
+ assert(!node_a.equal?(node_a2))
95
+ end
96
+
97
+ def test_equality_nil
98
+ node = @doc.root
99
+ assert(node != nil)
100
+ end
101
+
102
+ def test_equality_wrong_type
103
+ node = @doc.root
104
+
105
+ assert_raises(TypeError) do
106
+ assert(node != 'abc')
107
+ end
108
+ end
109
+
110
+ def test_content
111
+ assert_equal("An American heavy metal band formed in Los Angeles, California in 1981.British heavy metal band formed in 1975.",
112
+ @doc.root.content)
113
+
114
+ first = @doc.root.child
115
+ assert_equal('An American heavy metal band formed in Los Angeles, California in 1981.', first.content)
116
+ assert_equal('British heavy metal band formed in 1975.', first.next.content)
117
+ end
118
+
119
+ def test_base
120
+ doc = XML::Parser.string('<person />').parse
121
+ assert_nil(doc.root.base)
122
+ end
123
+
124
+ # We use the same facility that libXSLT does here to disable output escaping.
125
+ # This lets you specify that the node's content should be rendered unaltered
126
+ # whenever it is being output. This is useful for things like <script> and
127
+ # <style> nodes in HTML documents if you don't want to be forced to wrap them
128
+ # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
129
+ # to preserve the content of any of the text nodes.
130
+ #
131
+ def test_output_escaping
132
+ text = '<bad-script>if (a &lt; b || b &gt; c) { return "text"; }<stop/>return "&gt;&gt;&gt;snip&lt;&lt;&lt;";</bad-script>'
133
+ node = XML::Parser.string(text).parse.root
134
+ assert_equal text, node.to_s
135
+
136
+ text_noenc = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
137
+ node.output_escaping = false
138
+ assert_equal text_noenc, node.to_s
139
+
140
+ node.output_escaping = true
141
+ assert_equal text, node.to_s
142
+
143
+ node.output_escaping = nil
144
+ assert_equal text_noenc, node.to_s
145
+
146
+ node.output_escaping = true
147
+ assert_equal text, node.to_s
148
+ end
149
+
150
+ # Just a sanity check for output escaping.
151
+ def test_output_escaping_sanity
152
+ text = '<bad-script>if (a &lt; b || b &gt; c) { return "text"; }<stop/>return "&gt;&gt;&gt;snip&lt;&lt;&lt;";</bad-script>'
153
+ node = XML::Parser.string(text).parse.root
154
+ affected = node.find('//text()')
155
+
156
+ check_escaping = lambda do |flag|
157
+ assert_equal('bad-script', node.name)
158
+ assert_equal(flag, node.output_escaping?)
159
+ affected.each do |x|
160
+ assert_equal(flag ? 'text' : 'textnoenc', x.name)
161
+ assert_equal(flag, x.output_escaping?)
162
+ end
163
+ end
164
+
165
+ node.output_escaping = false
166
+ check_escaping[false]
167
+
168
+ node.output_escaping = true
169
+ check_escaping[true]
170
+
171
+ node.output_escaping = nil
172
+ check_escaping[false]
173
+
174
+ node.output_escaping = true
175
+ check_escaping[true]
176
+
177
+ affected.first.output_escaping = true
178
+ affected.last.output_escaping = false
179
+ assert node.output_escaping?.nil?
180
+ end
181
+ end
@@ -0,0 +1,49 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class CDataCommentTest < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.string('<root></root>')
7
+ @doc = xp.parse
8
+ assert_instance_of(XML::Document, @doc)
9
+ @root = @doc.root
10
+ end
11
+
12
+ def test_node_type
13
+ cnode = XML::Node.new_cdata('test cdata')
14
+ assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
15
+ end
16
+
17
+ def test_add_cdata
18
+ @root << XML::Node.new_cdata('mycdata')
19
+ assert_equal '<root><![CDATA[mycdata]]></root>',
20
+ @root.to_s.gsub(/\n\s*/,'')
21
+ end
22
+
23
+ def test_add_cdata_2
24
+ @root << XML::Node.new_cdata('mycdata')
25
+ assert_equal 'cdata',
26
+ @root.child.node_type_name
27
+ end
28
+
29
+ def test_add_cdata_3
30
+ @root << el = XML::Node.new_cdata('mycdata')
31
+ el << "_this_is_added"
32
+ assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
33
+ @root.to_s.gsub(/\n\s*/,'')
34
+ end
35
+
36
+ def test_attributes
37
+ cnode = XML::Node.new_cdata('test cdata')
38
+ assert_equal(0, cnode.attributes.length)
39
+ end
40
+
41
+ def test_set_cdata_attribute
42
+ cnode = XML::Node.new_cdata('test cdata')
43
+
44
+ # Can't create attributes on non-element nodes
45
+ assert_raise(ArgumentError) do
46
+ cnode['attr'] = '123'
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class NodeCommentTest < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.string('<root></root>')
7
+ @doc = xp.parse
8
+ assert_instance_of(XML::Document, @doc)
9
+ @root = @doc.root
10
+ end
11
+
12
+ def test_libxml_node_add_comment_01
13
+ @root << XML::Node.new_comment('mycomment')
14
+ assert_equal '<root><!--mycomment--></root>',
15
+ @root.to_s.gsub(/\n\s*/,'')
16
+ end
17
+
18
+ def test_libxml_node_add_comment_02
19
+ @root << XML::Node.new_comment('mycomment')
20
+ assert_equal 'comment',
21
+ @root.child.node_type_name
22
+ end
23
+
24
+ def test_libxml_node_add_comment_03
25
+ @root << el = XML::Node.new_comment('mycomment')
26
+ el << "_this_is_added"
27
+ assert_equal '<root><!--mycomment_this_is_added--></root>',
28
+ @root.to_s.gsub(/\n\s*/,'')
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ # see mailing list archive
5
+ # [libxml-devel] Segmentation fault when add the cloned/copied node
6
+ # 2007/11/27 20:51
7
+
8
+ class TestNodeCopy < Test::Unit::TestCase
9
+ def setup
10
+ str = <<-STR
11
+ <html><body>
12
+ <div class="textarea" id="t1" style="STATIC">foo</div>
13
+ <div class="textarea" id="t2" style="STATIC">bar</div>
14
+ </body></html>
15
+ STR
16
+
17
+ doc = XML::Parser.string(str).parse
18
+
19
+ xpath = "//div"
20
+ @div1 = doc.find(xpath).to_a[0]
21
+ @div2 = doc.find(xpath).to_a[1]
22
+ end
23
+
24
+ def test_libxml_node_copy_not_segv
25
+ @div2.each do |child|
26
+ c = child.copy(false)
27
+ @div1.child_add(c)
28
+ end
29
+ assert @div1.to_s =~ /foo/
30
+ end
31
+
32
+ def test_libxml_node_clone_not_segv
33
+ @div2.each do |child|
34
+ c = child.clone
35
+ @div1.child_add(c)
36
+ end
37
+ assert @div1.to_s =~ /foo/
38
+ end
39
+
40
+ end # TC_XML_Node_Copy