libxml-jruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.txt +4 -0
  2. data/README.txt +50 -0
  3. data/Rakefile +19 -0
  4. data/VERSION +1 -0
  5. data/VERSION.yml +5 -0
  6. data/lib/libxml-jruby.rb +84 -0
  7. data/lib/libxml-jruby/xml.rb +1 -0
  8. data/lib/libxml-jruby/xml/attr.rb +46 -0
  9. data/lib/libxml-jruby/xml/attributes.rb +68 -0
  10. data/lib/libxml-jruby/xml/document.rb +52 -0
  11. data/lib/libxml-jruby/xml/dtd.rb +25 -0
  12. data/lib/libxml-jruby/xml/node.rb +285 -0
  13. data/lib/libxml-jruby/xml/ns.rb +19 -0
  14. data/lib/libxml-jruby/xml/parser.rb +121 -0
  15. data/lib/libxml-jruby/xml/xpath.rb +98 -0
  16. data/lib/libxml.rb +1 -0
  17. data/lib/xml.rb +13 -0
  18. data/lib/xml/libxml.rb +8 -0
  19. data/test/etc_doc_to_s.rb +19 -0
  20. data/test/ets_copy_bug.rb +21 -0
  21. data/test/ets_copy_bug3.rb +38 -0
  22. data/test/ets_doc_file.rb +15 -0
  23. data/test/ets_doc_to_s.rb +21 -0
  24. data/test/ets_gpx.rb +26 -0
  25. data/test/ets_node_gc.rb +21 -0
  26. data/test/ets_tsr.rb +9 -0
  27. data/test/model/default_validation_bug.rb +0 -0
  28. data/test/tc_attributes.rb +110 -0
  29. data/test/tc_deprecated_require.rb +13 -0
  30. data/test/tc_document.rb +97 -0
  31. data/test/tc_document_write.rb +139 -0
  32. data/test/tc_dtd.rb +70 -0
  33. data/test/tc_html_parser.rb +63 -0
  34. data/test/tc_node.rb +108 -0
  35. data/test/tc_node_attr.rb +176 -0
  36. data/test/tc_node_cdata.rb +51 -0
  37. data/test/tc_node_comment.rb +32 -0
  38. data/test/tc_node_copy.rb +40 -0
  39. data/test/tc_node_edit.rb +98 -0
  40. data/test/tc_node_set.rb +24 -0
  41. data/test/tc_node_set2.rb +37 -0
  42. data/test/tc_node_text.rb +17 -0
  43. data/test/tc_node_xlink.rb +28 -0
  44. data/test/tc_ns.rb +18 -0
  45. data/test/tc_parser.rb +308 -0
  46. data/test/tc_parser_context.rb +126 -0
  47. data/test/tc_properties.rb +37 -0
  48. data/test/tc_reader.rb +112 -0
  49. data/test/tc_relaxng.rb +39 -0
  50. data/test/tc_sax_parser.rb +113 -0
  51. data/test/tc_schema.rb +39 -0
  52. data/test/tc_traversal.rb +220 -0
  53. data/test/tc_well_formed.rb +11 -0
  54. data/test/tc_xinclude.rb +26 -0
  55. data/test/tc_xpath.rb +130 -0
  56. data/test/tc_xpath_context.rb +72 -0
  57. data/test/tc_xpointer.rb +78 -0
  58. data/test/test_libxml-jruby.rb +0 -0
  59. data/test/test_suite.rb +31 -0
  60. data/test/ts_working.rb +31 -0
  61. metadata +121 -0
@@ -0,0 +1,11 @@
1
+ require "libxml"
2
+ require 'test/unit'
3
+
4
+ class TestWellFormed < Test::Unit::TestCase
5
+ def test_xml_node_doc_get()
6
+ parser = XML::Parser.new
7
+ parser.string = "<p>I am well formed</p>"
8
+ assert(parser.context.well_formed?)
9
+ end
10
+ end
11
+
@@ -0,0 +1,26 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestXInclude < Test::Unit::TestCase
5
+ def setup
6
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml'))
7
+ assert_instance_of(XML::Document, @doc)
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def test_ruby_xml_xinclude
15
+ expected = <<-EOS
16
+ <?xml version="1.0"?>
17
+ <document xmlns:xi="http://www.w3.org/2001/XInclude">
18
+ <p>This libxml2 binding has the following project information:
19
+ <code>This is some text to include in an xml file via XInclude.</code></p>
20
+ </document>
21
+ EOS
22
+
23
+ assert_equal(1, @doc.xinclude)
24
+ assert_equal(expected, @doc.to_s)
25
+ end
26
+ end
@@ -0,0 +1,130 @@
1
+ require 'xml'
2
+ require "tempfile"
3
+ require "test/unit"
4
+
5
+ class TestXPath < Test::Unit::TestCase
6
+ def setup
7
+ @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def test_doc_find
15
+ nodes = @doc.find('/soap:Envelope')
16
+ assert_instance_of(XML::XPath::Object, nodes)
17
+ assert_equal(1, nodes.length)
18
+ assert_equal(nodes.xpath_type, XML::XPath::NODESET)
19
+ assert_instance_of(XML::Node::Set, nodes.set)
20
+ assert_instance_of(XML::XPath::Context, nodes.context)
21
+ end
22
+
23
+ def test_doc_find_first
24
+ node = @doc.find_first('/soap:Envelope/soap:Body')
25
+ assert_instance_of(XML::Node, node)
26
+ end
27
+
28
+ def test_ns
29
+ nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
30
+ assert_equal(3, nodes.length)
31
+ end
32
+
33
+ def test_ns_array
34
+ nodes = @doc.find('//ns1:IdAndName', ['ns1:http://domain.somewhere.com'])
35
+ assert_equal(3, nodes.length)
36
+ end
37
+
38
+ def test_default_ns
39
+ # Pull all nodes with http://services.somewhere.com namespace
40
+ nodes = @doc.find('//*[namespace-uri()="http://services.somewhere.com"]')
41
+ assert_equal(2, nodes.length)
42
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
43
+ assert_equal('IDAndNameList', nodes[1].name)
44
+
45
+ # Pull all nodes with http://services.somewhere.com namespace
46
+ nodes = @doc.find('//ns:*', 'ns:http://services.somewhere.com')
47
+ assert_equal(2, nodes.length)
48
+ assert_equal('getManufacturerNamesResponse', nodes[0].name)
49
+ assert_equal('IDAndNameList', nodes[1].name)
50
+
51
+ # Get getManufacturerNamesResponse node
52
+ nodes = @doc.find('//ns:getManufacturerNamesResponse', 'ns:http://services.somewhere.com')
53
+ assert_equal(1, nodes.length)
54
+
55
+ # Get IdAndName node
56
+ nodes = @doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
57
+ ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
58
+ assert_equal(3, nodes.length)
59
+ end
60
+
61
+ def test_attribute_ns
62
+ # Pull all nodes with http://services.somewhere.com namespace
63
+ nodes = @doc.find('@soap:encodingStyle')
64
+ assert_equal(1, nodes.length)
65
+ assert_equal('encodingStyle', nodes.first.name)
66
+ assert_equal('http://www.w3.org/2001/12/soap-encoding', nodes.first.value)
67
+ end
68
+
69
+ def test_node_find
70
+ nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
71
+ node = nodes.first
72
+
73
+ # Since we are searching on the node, don't have to register namespace
74
+ nodes = node.find('ns1:name')
75
+ assert_equal(1, nodes.length)
76
+ assert_equal('name', nodes.first.name)
77
+ assert_equal('man1', nodes.first.content)
78
+ end
79
+
80
+ def test_node_find_first
81
+ node = @doc.find_first('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
82
+
83
+ # Since we are searching on the node, don't have to register namespace
84
+ node = node.find_first('ns1:name')
85
+ assert_equal('name', node.name)
86
+ assert_equal('man1', node.content)
87
+ end
88
+
89
+ def test_node_no_doc
90
+ node = XML::Node.new('header', 'some content')
91
+ assert_raise(TypeError) do
92
+ node = node.find_first('/header')
93
+ end
94
+ end
95
+
96
+ def test_nodes_debug
97
+ # nodes = @doc.find('//ns1:IdAndName', 'ns1:http://domain.somewhere.com')
98
+ #nodes.debug
99
+ end
100
+
101
+ #def test_custom_function
102
+ #xml = Tempfile.new("xxx")
103
+ #xml.puts("<a/>")
104
+ #xml.close
105
+
106
+ #doc = XML::Document.file(xml.path)
107
+ #assert_nil(doc.find("//*[name(.)=normalize_space(' a ')]"))
108
+ #end
109
+
110
+ #def test_memory
111
+ ## This sometimes causes a segmentation fault because
112
+ ## an xml document is sometimes freed before the
113
+ ## xpath_object used to query it. When the xpath_object
114
+ ## is free, it iterates over its results which are pointers
115
+ ## to the document's nodes. A segmentation fault then happens.
116
+
117
+ #100.times do
118
+ #doc = XML::Document.new('1.0')
119
+ #doc.root = XML::Node.new("header")
120
+
121
+ #1000.times do
122
+ #doc.root << XML::Node.new("footer")
123
+ #end
124
+
125
+ #nodes = doc.find('/header/footer')
126
+ #nodes.length
127
+ #nodes = nil
128
+ #end
129
+ #end
130
+ end
@@ -0,0 +1,72 @@
1
+ require 'xml'
2
+ require "tempfile"
3
+ require "test/unit"
4
+
5
+ class TestXPathContext < Test::Unit::TestCase
6
+ SOAP_PREFIX = 'soap'
7
+ SOAP_URI = 'http://schemas.xmlsoap.org/soap/envelope/'
8
+
9
+ NS0_PREFIX = 'ns0'
10
+ NS0_URI = 'http://services.somewhere.com'
11
+
12
+ def setup()
13
+ doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
14
+ @context = XML::XPath::Context.new(doc)
15
+ end
16
+
17
+ def teardown()
18
+ @context = nil
19
+ end
20
+
21
+ #def test_no_ns
22
+ #assert_raise(XML::XPath::InvalidPath) do
23
+ #@context.find('/soap:Envelope')
24
+ #end
25
+ #end
26
+
27
+ def test_ns_register
28
+ @context.register_namespace(SOAP_PREFIX, SOAP_URI)
29
+ @context.register_namespace(NS0_PREFIX, NS0_URI)
30
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
31
+ assert_equal(1, nodes.length)
32
+ end
33
+
34
+ def test_ns_register_string
35
+ @context.register_namespaces("#{SOAP_PREFIX}:#{SOAP_URI}")
36
+ @context.register_namespaces("#{NS0_PREFIX}:#{NS0_URI}")
37
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
38
+ assert_equal(1, nodes.length)
39
+ end
40
+
41
+ def test_ns_register_array
42
+ @context.register_namespaces(["#{SOAP_PREFIX}:#{SOAP_URI}", "#{NS0_PREFIX}:#{NS0_URI}"])
43
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
44
+ assert_equal(1, nodes.length)
45
+ end
46
+
47
+ def test_ns_register_hash
48
+ @context.register_namespaces(SOAP_PREFIX => SOAP_URI,
49
+ NS0_PREFIX => NS0_URI)
50
+
51
+ nodes = @context.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse')
52
+ assert_equal(1, nodes.length)
53
+ end
54
+
55
+ def test_ns_register_node
56
+ @context.register_namespaces_from_node(@context.doc.root)
57
+ nodes = @context.find('/soap:Envelope')
58
+ assert_equal(1, nodes.length)
59
+ end
60
+
61
+ def test_node
62
+ @context.register_namespaces_from_node(@context.doc.root)
63
+
64
+ nodes = @context.find('soap:Body')
65
+ assert_equal(0, nodes.length)
66
+
67
+
68
+ @context.node = @context.doc.root.child.next
69
+ nodes = @context.find('soap:Body')
70
+ assert_equal(0, nodes.length)
71
+ end
72
+ end
@@ -0,0 +1,78 @@
1
+ require 'xml'
2
+ require "test/unit"
3
+
4
+ class TC_XML_XPointer < Test::Unit::TestCase
5
+ def setup()
6
+ xp = XML::Parser.new()
7
+ str = '<!DOCTYPE ra [<!ELEMENT ra (foo+)><!ATTLIST ra id ID #IMPLIED><!ELEMENT foo (#PCDATA)><!ATTLIST foo id ID #IMPLIED>]><ra id="start"><foo id="one">one</foo><foo id="two">two</foo><foo id="three">three</foo></ra>'
8
+ assert_equal(str, xp.string = str)
9
+ @doc = xp.parse
10
+ assert_instance_of(XML::Document, @doc)
11
+ @root = @doc.root
12
+ assert_instance_of(XML::Node, @root)
13
+ end
14
+
15
+ def teardown()
16
+ @doc = nil
17
+ @root = nil
18
+ @xptr = nil
19
+ end
20
+
21
+ def test_libxml_xpointer_id()
22
+ @xptr = @root.pointer('xpointer(id("two"))')
23
+ assert_instance_of(XML::XPath::Object, @xptr)
24
+ set = @xptr.set
25
+ assert_instance_of(XML::Node::Set, set)
26
+ for n in set
27
+ # It seems from the spec that the pointer should
28
+ # be the whole node, rather than just the ID attr.
29
+
30
+ # assert_equal('two', n.to_s)
31
+
32
+ assert_instance_of(XML::Node, n)
33
+ assert_equal('two', n['id'])
34
+ end
35
+
36
+ # FIXME: Not sure at all about this kind of range
37
+ if ENV['NOTWORKING']
38
+ @xptr = @root.pointer('xpointer(id("two")) xpointer(id("three"))')
39
+ assert_instance_of(XML::XPath, @xptr)
40
+ assert_instance_of(XML::Node::Set, @xptr.set)
41
+ assert_equal(2, @xptr.set.length)
42
+ for n in @xptr.set
43
+ assert_match(/two|three/, n.to_s)
44
+ end
45
+ end
46
+ end
47
+
48
+ # FIXME: There is a bug in these ranges...
49
+ if ENV['NOTWORKING']
50
+ def test_libxml_xpointer_range()
51
+ nstart = nend = nil
52
+ @xptr = @root.pointer('xpointer(id("one"))').set
53
+ @xptr.each{|n| nstart = n}
54
+ assert_instance_of(XML::Node, nstart)
55
+ @xptr = @root.pointer('xpointer(id("three"))').set
56
+ @xptr.each{|n| nend = n}
57
+ assert_instance_of(XML::Node, nend)
58
+ range = XML::XPointer.range(nstart, nend)
59
+ assert_instance_of(XML::XPath, range)
60
+ assert_instance_of(XML::Node::Set, range.set)
61
+
62
+ for n in range.set
63
+ assert_match(/one|two|three/, n.to_s)
64
+ end
65
+ assert_equal(3, range.set.length)
66
+ end
67
+ end
68
+
69
+ # def test_libxml_xpointer_start_point()
70
+ # @xptr = @root.pointer('xpointer(start-point("one"))')
71
+ # assert_instance_of(XML::XPath, @xptr)
72
+ # set = @xptr.set
73
+ # assert_instance_of(XML::Node::Set, set)
74
+ # for n in set
75
+ # assert_match(/one|two|three/, n.to_s)
76
+ # end
77
+ # end
78
+ end
File without changes
@@ -0,0 +1,31 @@
1
+ require 'tc_well_formed'
2
+ require 'tc_attributes'
3
+ require 'tc_document'
4
+ require 'tc_document_write'
5
+ require 'tc_dtd'
6
+ require 'tc_html_parser'
7
+ require 'tc_node'
8
+ require 'tc_node_attr'
9
+ require 'tc_node_cdata'
10
+ require 'tc_node_comment'
11
+ require 'tc_node_copy'
12
+ require 'tc_node_edit'
13
+ require 'tc_node_set'
14
+ require 'tc_node_set2'
15
+ require 'tc_node_text'
16
+ require 'tc_node_xlink'
17
+ require 'tc_ns'
18
+ require 'tc_parser'
19
+ require 'tc_parser_context'
20
+ require 'tc_reader'
21
+ require 'tc_relaxng'
22
+ require 'tc_sax_parser'
23
+ require 'tc_schema'
24
+ require 'tc_traversal'
25
+ require 'tc_xinclude'
26
+ require 'tc_xpath'
27
+ require 'tc_xpointer'
28
+
29
+ # Compatibility
30
+ require 'tc_properties'
31
+ require 'tc_deprecated_require'
@@ -0,0 +1,31 @@
1
+ # require 'tc_well_formed' FIXME Parser#context not implemented
2
+ require 'tc_attributes'
3
+ require 'tc_document'
4
+ # require 'tc_document_write' FIXME Document#write not implemented
5
+ # require 'tc_dtd' FIXME Issues with reading a Schema from a string
6
+ # require 'tc_html_parser' FIXME HTMLParser not implemented
7
+ require 'tc_node'
8
+ require 'tc_node_attr'
9
+ # require 'tc_node_cdata' FIXME Node#new_cdata
10
+ # require 'tc_node_comment' FIXME Node#new_comment
11
+ require 'tc_node_copy'
12
+ # require 'tc_node_edit' FIXME Not implemented
13
+ require 'tc_node_set'
14
+ require 'tc_node_set2'
15
+ # require 'tc_node_text' FIXME Node#new_text
16
+ # require 'tc_node_xlink' FIXME Not implemented
17
+ require 'tc_ns'
18
+ require 'tc_parser'
19
+ # require 'tc_parser_context' FIXME Not implemented
20
+ # require 'tc_reader' FIXME Not implemented
21
+ # require 'tc_relaxng' FIXME Not implemented
22
+ # require 'tc_sax_parser' FIXME show stopping error
23
+ # require 'tc_schema' FIXME treat string like file?
24
+ require 'tc_traversal'
25
+ # require 'tc_xinclude' FIXME Not implemented
26
+ # require 'tc_xpath' FIXME this is partially implemented
27
+ # require 'tc_xpointer' FIXME Not implemented
28
+
29
+ # Compatibility
30
+ require 'tc_properties'
31
+ require 'tc_deprecated_require'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libxml-jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Michael Guterl
13
+ - Uwe L. Korn
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-04-07 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Lixml replacement for JRuby in 100% Java
23
+ email: uwelk@xhochy.org
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.txt
30
+ files:
31
+ - History.txt
32
+ - README.txt
33
+ - Rakefile
34
+ - VERSION
35
+ - VERSION.yml
36
+ - lib/libxml-jruby.rb
37
+ - lib/libxml-jruby/xml.rb
38
+ - lib/libxml-jruby/xml/attr.rb
39
+ - lib/libxml-jruby/xml/attributes.rb
40
+ - lib/libxml-jruby/xml/document.rb
41
+ - lib/libxml-jruby/xml/dtd.rb
42
+ - lib/libxml-jruby/xml/node.rb
43
+ - lib/libxml-jruby/xml/ns.rb
44
+ - lib/libxml-jruby/xml/parser.rb
45
+ - lib/libxml-jruby/xml/xpath.rb
46
+ - lib/libxml.rb
47
+ - lib/xml.rb
48
+ - lib/xml/libxml.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/xhochy/libxml-jruby
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.6
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Libxml replacement for JRuby
79
+ test_files:
80
+ - test/tc_node_copy.rb
81
+ - test/tc_well_formed.rb
82
+ - test/tc_node_attr.rb
83
+ - test/ets_copy_bug3.rb
84
+ - test/tc_node_xlink.rb
85
+ - test/tc_document.rb
86
+ - test/tc_properties.rb
87
+ - test/ets_gpx.rb
88
+ - test/tc_html_parser.rb
89
+ - test/tc_document_write.rb
90
+ - test/tc_xpointer.rb
91
+ - test/tc_attributes.rb
92
+ - test/tc_dtd.rb
93
+ - test/ets_node_gc.rb
94
+ - test/ets_doc_to_s.rb
95
+ - test/test_suite.rb
96
+ - test/tc_node_set.rb
97
+ - test/tc_schema.rb
98
+ - test/tc_node_text.rb
99
+ - test/etc_doc_to_s.rb
100
+ - test/tc_node_comment.rb
101
+ - test/ts_working.rb
102
+ - test/tc_deprecated_require.rb
103
+ - test/tc_node_cdata.rb
104
+ - test/tc_node_set2.rb
105
+ - test/tc_relaxng.rb
106
+ - test/tc_node.rb
107
+ - test/tc_xpath_context.rb
108
+ - test/ets_doc_file.rb
109
+ - test/tc_parser.rb
110
+ - test/tc_parser_context.rb
111
+ - test/ets_copy_bug.rb
112
+ - test/tc_ns.rb
113
+ - test/tc_xpath.rb
114
+ - test/tc_node_edit.rb
115
+ - test/tc_reader.rb
116
+ - test/tc_traversal.rb
117
+ - test/tc_sax_parser.rb
118
+ - test/test_libxml-jruby.rb
119
+ - test/ets_tsr.rb
120
+ - test/tc_xinclude.rb
121
+ - test/model/default_validation_bug.rb