libxml-ruby 2.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +790 -0
  3. data/LICENSE +21 -0
  4. data/MANIFEST +166 -0
  5. data/README.rdoc +184 -0
  6. data/Rakefile +81 -0
  7. data/ext/libxml/extconf.h +4 -0
  8. data/ext/libxml/extconf.rb +57 -0
  9. data/ext/libxml/libxml.c +80 -0
  10. data/ext/libxml/libxml_ruby.def +35 -0
  11. data/ext/libxml/ruby_libxml.h +75 -0
  12. data/ext/libxml/ruby_xml.c +977 -0
  13. data/ext/libxml/ruby_xml.h +20 -0
  14. data/ext/libxml/ruby_xml_attr.c +333 -0
  15. data/ext/libxml/ruby_xml_attr.h +12 -0
  16. data/ext/libxml/ruby_xml_attr_decl.c +153 -0
  17. data/ext/libxml/ruby_xml_attr_decl.h +11 -0
  18. data/ext/libxml/ruby_xml_attributes.c +275 -0
  19. data/ext/libxml/ruby_xml_attributes.h +15 -0
  20. data/ext/libxml/ruby_xml_cbg.c +85 -0
  21. data/ext/libxml/ruby_xml_document.c +1133 -0
  22. data/ext/libxml/ruby_xml_document.h +11 -0
  23. data/ext/libxml/ruby_xml_dtd.c +261 -0
  24. data/ext/libxml/ruby_xml_dtd.h +9 -0
  25. data/ext/libxml/ruby_xml_encoding.c +262 -0
  26. data/ext/libxml/ruby_xml_encoding.h +19 -0
  27. data/ext/libxml/ruby_xml_error.c +996 -0
  28. data/ext/libxml/ruby_xml_error.h +12 -0
  29. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  30. data/ext/libxml/ruby_xml_html_parser.h +10 -0
  31. data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
  32. data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
  33. data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
  34. data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
  35. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  36. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  37. data/ext/libxml/ruby_xml_io.c +52 -0
  38. data/ext/libxml/ruby_xml_io.h +10 -0
  39. data/ext/libxml/ruby_xml_namespace.c +153 -0
  40. data/ext/libxml/ruby_xml_namespace.h +10 -0
  41. data/ext/libxml/ruby_xml_namespaces.c +293 -0
  42. data/ext/libxml/ruby_xml_namespaces.h +9 -0
  43. data/ext/libxml/ruby_xml_node.c +1446 -0
  44. data/ext/libxml/ruby_xml_node.h +11 -0
  45. data/ext/libxml/ruby_xml_parser.c +94 -0
  46. data/ext/libxml/ruby_xml_parser.h +12 -0
  47. data/ext/libxml/ruby_xml_parser_context.c +999 -0
  48. data/ext/libxml/ruby_xml_parser_context.h +10 -0
  49. data/ext/libxml/ruby_xml_parser_options.c +66 -0
  50. data/ext/libxml/ruby_xml_parser_options.h +12 -0
  51. data/ext/libxml/ruby_xml_reader.c +1226 -0
  52. data/ext/libxml/ruby_xml_reader.h +17 -0
  53. data/ext/libxml/ruby_xml_relaxng.c +110 -0
  54. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  55. data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
  56. data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
  57. data/ext/libxml/ruby_xml_sax_parser.c +120 -0
  58. data/ext/libxml/ruby_xml_sax_parser.h +10 -0
  59. data/ext/libxml/ruby_xml_schema.c +300 -0
  60. data/ext/libxml/ruby_xml_schema.h +809 -0
  61. data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
  62. data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
  63. data/ext/libxml/ruby_xml_schema_element.c +94 -0
  64. data/ext/libxml/ruby_xml_schema_element.h +14 -0
  65. data/ext/libxml/ruby_xml_schema_facet.c +52 -0
  66. data/ext/libxml/ruby_xml_schema_facet.h +13 -0
  67. data/ext/libxml/ruby_xml_schema_type.c +259 -0
  68. data/ext/libxml/ruby_xml_schema_type.h +9 -0
  69. data/ext/libxml/ruby_xml_version.h +9 -0
  70. data/ext/libxml/ruby_xml_writer.c +1136 -0
  71. data/ext/libxml/ruby_xml_writer.h +10 -0
  72. data/ext/libxml/ruby_xml_xinclude.c +16 -0
  73. data/ext/libxml/ruby_xml_xinclude.h +11 -0
  74. data/ext/libxml/ruby_xml_xpath.c +188 -0
  75. data/ext/libxml/ruby_xml_xpath.h +13 -0
  76. data/ext/libxml/ruby_xml_xpath_context.c +360 -0
  77. data/ext/libxml/ruby_xml_xpath_context.h +9 -0
  78. data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
  79. data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
  80. data/ext/libxml/ruby_xml_xpath_object.c +335 -0
  81. data/ext/libxml/ruby_xml_xpath_object.h +17 -0
  82. data/ext/libxml/ruby_xml_xpointer.c +99 -0
  83. data/ext/libxml/ruby_xml_xpointer.h +11 -0
  84. data/ext/vc/libxml_ruby.sln +26 -0
  85. data/lib/2.3/libxml_ruby.so +0 -0
  86. data/lib/libs/libiconv-2.dll +0 -0
  87. data/lib/libs/libxml2-2.dll +0 -0
  88. data/lib/libs/zlib1.dll +0 -0
  89. data/lib/libxml.rb +35 -0
  90. data/lib/libxml/attr.rb +123 -0
  91. data/lib/libxml/attr_decl.rb +80 -0
  92. data/lib/libxml/attributes.rb +14 -0
  93. data/lib/libxml/document.rb +194 -0
  94. data/lib/libxml/error.rb +95 -0
  95. data/lib/libxml/hpricot.rb +78 -0
  96. data/lib/libxml/html_parser.rb +96 -0
  97. data/lib/libxml/namespace.rb +62 -0
  98. data/lib/libxml/namespaces.rb +38 -0
  99. data/lib/libxml/node.rb +399 -0
  100. data/lib/libxml/ns.rb +22 -0
  101. data/lib/libxml/parser.rb +367 -0
  102. data/lib/libxml/properties.rb +23 -0
  103. data/lib/libxml/reader.rb +29 -0
  104. data/lib/libxml/sax_callbacks.rb +180 -0
  105. data/lib/libxml/sax_parser.rb +58 -0
  106. data/lib/libxml/schema.rb +67 -0
  107. data/lib/libxml/schema/attribute.rb +19 -0
  108. data/lib/libxml/schema/element.rb +27 -0
  109. data/lib/libxml/schema/type.rb +29 -0
  110. data/lib/libxml/tree.rb +29 -0
  111. data/lib/libxml/xpath_object.rb +16 -0
  112. data/lib/xml.rb +14 -0
  113. data/lib/xml/libxml.rb +10 -0
  114. data/libxml-ruby.gemspec +47 -0
  115. data/script/benchmark/depixelate +634 -0
  116. data/script/benchmark/hamlet.xml +9055 -0
  117. data/script/benchmark/parsecount +170 -0
  118. data/script/benchmark/sock_entries.xml +507 -0
  119. data/script/benchmark/throughput +41 -0
  120. data/script/test +6 -0
  121. data/setup.rb +1585 -0
  122. data/test/c14n/given/doc.dtd +1 -0
  123. data/test/c14n/given/example-1.xml +14 -0
  124. data/test/c14n/given/example-2.xml +11 -0
  125. data/test/c14n/given/example-3.xml +18 -0
  126. data/test/c14n/given/example-4.xml +9 -0
  127. data/test/c14n/given/example-5.xml +12 -0
  128. data/test/c14n/given/example-6.xml +2 -0
  129. data/test/c14n/given/example-7.xml +11 -0
  130. data/test/c14n/given/example-8.xml +11 -0
  131. data/test/c14n/given/example-8.xpath +10 -0
  132. data/test/c14n/given/world.txt +1 -0
  133. data/test/c14n/result/1-1-without-comments/example-1 +4 -0
  134. data/test/c14n/result/1-1-without-comments/example-2 +11 -0
  135. data/test/c14n/result/1-1-without-comments/example-3 +14 -0
  136. data/test/c14n/result/1-1-without-comments/example-4 +9 -0
  137. data/test/c14n/result/1-1-without-comments/example-5 +3 -0
  138. data/test/c14n/result/1-1-without-comments/example-6 +1 -0
  139. data/test/c14n/result/1-1-without-comments/example-7 +1 -0
  140. data/test/c14n/result/1-1-without-comments/example-8 +1 -0
  141. data/test/c14n/result/with-comments/example-1 +6 -0
  142. data/test/c14n/result/with-comments/example-2 +11 -0
  143. data/test/c14n/result/with-comments/example-3 +14 -0
  144. data/test/c14n/result/with-comments/example-4 +9 -0
  145. data/test/c14n/result/with-comments/example-5 +4 -0
  146. data/test/c14n/result/with-comments/example-6 +1 -0
  147. data/test/c14n/result/with-comments/example-7 +1 -0
  148. data/test/c14n/result/without-comments/example-1 +4 -0
  149. data/test/c14n/result/without-comments/example-2 +11 -0
  150. data/test/c14n/result/without-comments/example-3 +14 -0
  151. data/test/c14n/result/without-comments/example-4 +9 -0
  152. data/test/c14n/result/without-comments/example-5 +3 -0
  153. data/test/c14n/result/without-comments/example-6 +1 -0
  154. data/test/c14n/result/without-comments/example-7 +1 -0
  155. data/test/model/atom.xml +13 -0
  156. data/test/model/bands.iso-8859-1.xml +5 -0
  157. data/test/model/bands.utf-8.xml +5 -0
  158. data/test/model/bands.xml +5 -0
  159. data/test/model/books.xml +154 -0
  160. data/test/model/merge_bug_data.xml +58 -0
  161. data/test/model/ruby-lang.html +238 -0
  162. data/test/model/rubynet.xml +79 -0
  163. data/test/model/rubynet_project +1 -0
  164. data/test/model/shiporder.rnc +28 -0
  165. data/test/model/shiporder.rng +86 -0
  166. data/test/model/shiporder.xml +23 -0
  167. data/test/model/shiporder.xsd +40 -0
  168. data/test/model/soap.xml +27 -0
  169. data/test/model/xinclude.xml +5 -0
  170. data/test/tc_attr.rb +181 -0
  171. data/test/tc_attr_decl.rb +132 -0
  172. data/test/tc_attributes.rb +142 -0
  173. data/test/tc_canonicalize.rb +124 -0
  174. data/test/tc_deprecated_require.rb +12 -0
  175. data/test/tc_document.rb +125 -0
  176. data/test/tc_document_write.rb +195 -0
  177. data/test/tc_dtd.rb +128 -0
  178. data/test/tc_encoding.rb +126 -0
  179. data/test/tc_encoding_sax.rb +115 -0
  180. data/test/tc_error.rb +179 -0
  181. data/test/tc_html_parser.rb +161 -0
  182. data/test/tc_html_parser_context.rb +23 -0
  183. data/test/tc_namespace.rb +61 -0
  184. data/test/tc_namespaces.rb +209 -0
  185. data/test/tc_node.rb +215 -0
  186. data/test/tc_node_cdata.rb +50 -0
  187. data/test/tc_node_comment.rb +32 -0
  188. data/test/tc_node_copy.rb +41 -0
  189. data/test/tc_node_edit.rb +174 -0
  190. data/test/tc_node_pi.rb +39 -0
  191. data/test/tc_node_text.rb +70 -0
  192. data/test/tc_node_write.rb +107 -0
  193. data/test/tc_node_xlink.rb +28 -0
  194. data/test/tc_parser.rb +375 -0
  195. data/test/tc_parser_context.rb +204 -0
  196. data/test/tc_properties.rb +38 -0
  197. data/test/tc_reader.rb +399 -0
  198. data/test/tc_relaxng.rb +53 -0
  199. data/test/tc_sax_parser.rb +319 -0
  200. data/test/tc_schema.rb +161 -0
  201. data/test/tc_traversal.rb +152 -0
  202. data/test/tc_writer.rb +447 -0
  203. data/test/tc_xinclude.rb +20 -0
  204. data/test/tc_xml.rb +225 -0
  205. data/test/tc_xpath.rb +244 -0
  206. data/test/tc_xpath_context.rb +88 -0
  207. data/test/tc_xpath_expression.rb +37 -0
  208. data/test/tc_xpointer.rb +72 -0
  209. data/test/test_helper.rb +16 -0
  210. data/test/test_suite.rb +49 -0
  211. metadata +344 -0
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <shiporder orderid="889923"
3
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi:noNamespaceSchemaLocation="shiporder.xsd">
5
+ <orderperson>John Smith</orderperson>
6
+ <shipto>
7
+ <name>Ola Nordmann</name>
8
+ <address>Langgt 23</address>
9
+ <city>4000 Stavanger</city>
10
+ <country>Norway</country>
11
+ </shipto>
12
+ <item>
13
+ <title>Empire Burlesque</title>
14
+ <note>Special Edition</note>
15
+ <quantity>1</quantity>
16
+ <price>10.90</price>
17
+ </item>
18
+ <item>
19
+ <title>Hide your heart</title>
20
+ <quantity>1</quantity>
21
+ <price>9.90</price>
22
+ </item>
23
+ </shiporder>
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="iso-8859-1" ?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3
+ <xs:element name="shiporder" type="shiporder"/>
4
+
5
+ <xs:complexType name="shiporder">
6
+ <xs:annotation>
7
+ <xs:documentation>Shiporder type documentation</xs:documentation>
8
+ </xs:annotation>
9
+ <xs:sequence>
10
+ <xs:element name="orderperson" type="xs:string">
11
+ <xs:annotation>
12
+ <xs:documentation>orderperson element documentation</xs:documentation>
13
+ </xs:annotation>
14
+ </xs:element>
15
+ <xs:element name="shipto">
16
+ <xs:complexType>
17
+ <xs:sequence>
18
+ <xs:element name="name" type="xs:string"/>
19
+ <xs:element name="address" type="xs:string"/>
20
+ <xs:element name="city" type="xs:string"/>
21
+ <xs:element name="country" type="xs:string"/>
22
+ </xs:sequence>
23
+ </xs:complexType>
24
+ </xs:element>
25
+ <xs:element name="item" maxOccurs="unbounded">
26
+ <xs:complexType>
27
+ <xs:sequence>
28
+ <xs:element name="title" type="xs:string"/>
29
+ <xs:element name="note" type="xs:string" minOccurs="0"/>
30
+ <xs:element name="quantity" type="xs:positiveInteger"/>
31
+ <xs:element name="price" type="xs:decimal"/>
32
+ </xs:sequence>
33
+ </xs:complexType>
34
+ </xs:element>
35
+ </xs:sequence>
36
+ <xs:attribute name="orderid" type="xs:string" use="required"/>
37
+ <xs:attribute name="foo" default="1" type="xs:integer" use="optional"/>
38
+ <xs:attribute name="bar" use="prohibited"/>
39
+ </xs:complexType>
40
+ </xs:schema>
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <soap:Envelope
3
+ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
4
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+ soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
7
+ <soap:Body>
8
+ <getManufacturerNamesResponse name="widgestRus" xmlns="http://services.somewhere.com">
9
+ <IDAndNameList xmlns="http://services.somewhere.com">
10
+ <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com">
11
+ <id xmlns="http://domain.somewhere.com">1</id>
12
+ <name xmlns="http://domain.somewhere.com">man1</name>
13
+
14
+ </ns1:IdAndName>
15
+ <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com">
16
+ <id xmlns="http://domain.somewhere.com">2</id>
17
+ <name xmlns="http://domain.somewhere.com">man2</name>
18
+
19
+ </ns1:IdAndName>
20
+ <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com">
21
+ <id xmlns="http://domain.somewhere.com">3</id>
22
+ <name xmlns="http://domain.somewhere.com">man3</name>
23
+ </ns1:IdAndName>
24
+ </IDAndNameList>
25
+ </getManufacturerNamesResponse>
26
+ </soap:Body>
27
+ </soap:Envelope>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0"?>
2
+ <document xmlns:xi="http://www.w3.org/2001/XInclude">
3
+ <p>This libxml2 binding has the following project information:
4
+ <code><xi:include href="rubynet_project" parse="text"/></code></p>
5
+ </document>
@@ -0,0 +1,181 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ class AttrNodeTest < Minitest::Test
6
+ def setup
7
+ xp = XML::Parser.string(<<-EOS)
8
+ <CityModel
9
+ xmlns="http://www.opengis.net/examples"
10
+ xmlns:city="http://www.opengis.net/examples"
11
+ xmlns:gml="http://www.opengis.net/gml"
12
+ xmlns:xlink="http://www.w3.org/1999/xlink"
13
+ xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
14
+ xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
15
+ <type>City</type>
16
+ <cityMember name="Cambridge"
17
+ xlink:type="simple"
18
+ xlink:title="Trinity Lane"
19
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
20
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
21
+ </CityModel>
22
+ EOS
23
+
24
+ @doc = xp.parse
25
+ end
26
+
27
+ def teardown
28
+ @doc = nil
29
+ end
30
+
31
+ def city_member
32
+ @doc.find('/city:CityModel/city:cityMember').first
33
+ end
34
+
35
+ def test_doc
36
+ refute_nil(@doc)
37
+ assert_equal(XML::Encoding::NONE, @doc.encoding)
38
+ end
39
+
40
+ def test_types
41
+ attribute = city_member.attributes.get_attribute('name')
42
+ assert_instance_of(XML::Attr, attribute)
43
+ assert_equal('attribute', attribute.node_type_name)
44
+ end
45
+
46
+ def test_name
47
+ attribute = city_member.attributes.get_attribute('name')
48
+ assert_equal('name', attribute.name)
49
+ assert_equal(Encoding::UTF_8, attribute.name.encoding) if defined?(Encoding)
50
+
51
+ attribute = city_member.attributes.get_attribute('href')
52
+ assert_equal('href', attribute.name)
53
+ assert_equal('xlink', attribute.ns.prefix)
54
+ assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
55
+
56
+ attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
57
+ assert_equal('href', attribute.name)
58
+ assert_equal('xlink', attribute.ns.prefix)
59
+ assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
60
+ end
61
+
62
+ def test_value
63
+ attribute = city_member.attributes.get_attribute('name')
64
+ assert_equal('Cambridge', attribute.value)
65
+ assert_equal(Encoding::UTF_8, attribute.value.encoding) if defined?(Encoding)
66
+
67
+ attribute = city_member.attributes.get_attribute('href')
68
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
69
+ end
70
+
71
+ def test_set_value
72
+ attribute = city_member.attributes.get_attribute('name')
73
+ attribute.value = 'London'
74
+ assert_equal('London', attribute.value)
75
+ assert_equal(Encoding::UTF_8, attribute.value.encoding) if defined?(Encoding)
76
+
77
+ attribute = city_member.attributes.get_attribute('href')
78
+ attribute.value = 'http://i.have.changed'
79
+ assert_equal('http://i.have.changed', attribute.value)
80
+ assert_equal(Encoding::UTF_8, attribute.value.encoding) if defined?(Encoding)
81
+ end
82
+
83
+ def test_set_nil
84
+ attribute = city_member.attributes.get_attribute('name')
85
+ assert_raises(TypeError) do
86
+ attribute.value = nil
87
+ end
88
+ end
89
+
90
+ def test_create
91
+ attributes = city_member.attributes
92
+ assert_equal(5, attributes.length)
93
+
94
+ attr = XML::Attr.new(city_member, 'size', '50,000')
95
+ assert_instance_of(XML::Attr, attr)
96
+
97
+ attributes = city_member.attributes
98
+ assert_equal(6, attributes.length)
99
+
100
+ assert_equal(attributes['size'], '50,000')
101
+ end
102
+
103
+ def test_create_on_node
104
+ attributes = city_member.attributes
105
+ assert_equal(5, attributes.length)
106
+
107
+ attributes['country'] = 'England'
108
+
109
+ attributes = city_member.attributes
110
+ assert_equal(6, attributes.length)
111
+
112
+ assert_equal(attributes['country'], 'England')
113
+ end
114
+
115
+ def test_create_ns
116
+ assert_equal(5, city_member.attributes.length)
117
+
118
+ ns = XML::Namespace.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
119
+ attr = XML::Attr.new(city_member, 'rating', 'rocks', ns)
120
+ assert_instance_of(XML::Attr, attr)
121
+ assert_equal('rating', attr.name)
122
+ assert_equal('rocks', attr.value)
123
+
124
+ attributes = city_member.attributes
125
+ assert_equal(6, attributes.length)
126
+
127
+ assert_equal('rocks', city_member['rating'])
128
+ end
129
+
130
+ def test_remove
131
+ attributes = city_member.attributes
132
+ assert_equal(5, attributes.length)
133
+
134
+ attribute = attributes.get_attribute('name')
135
+ refute_nil(attribute.parent)
136
+ assert(attribute.parent?)
137
+
138
+ attribute.remove!
139
+ assert_equal(4, attributes.length)
140
+
141
+ attribute = attributes.get_attribute('name')
142
+ assert_nil(attribute)
143
+ end
144
+
145
+ def test_first
146
+ attribute = city_member.attributes.first
147
+ assert_instance_of(XML::Attr, attribute)
148
+ assert_equal('name', attribute.name)
149
+ assert_equal('Cambridge', attribute.value)
150
+
151
+ attribute = attribute.next
152
+ assert_instance_of(XML::Attr, attribute)
153
+ assert_equal('type', attribute.name)
154
+ assert_equal('simple', attribute.value)
155
+
156
+ attribute = attribute.next
157
+ assert_instance_of(XML::Attr, attribute)
158
+ assert_equal('title', attribute.name)
159
+ assert_equal('Trinity Lane', attribute.value)
160
+
161
+ attribute = attribute.next
162
+ assert_instance_of(XML::Attr, attribute)
163
+ assert_equal('href', attribute.name)
164
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
165
+
166
+ attribute = attribute.next
167
+ assert_instance_of(XML::Attr, attribute)
168
+ assert_equal('remoteSchema', attribute.name)
169
+ assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
170
+
171
+ attribute = attribute.next
172
+ assert_nil(attribute)
173
+ end
174
+
175
+ def test_no_attributes
176
+ element = @doc.find('/city:CityModel/city:type').first
177
+
178
+ refute_nil(element.attributes)
179
+ assert_equal(0, element.attributes.length)
180
+ end
181
+ end
@@ -0,0 +1,132 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ class AttrDeclTest < Minitest::Test
6
+ def setup
7
+ xp = XML::Parser.string(<<-EOS)
8
+ <!DOCTYPE test [
9
+ <!ELEMENT root (property*)>
10
+ <!ELEMENT property EMPTY>
11
+ <!ATTLIST property name NMTOKEN #REQUIRED>
12
+ <!ATTLIST property access (r | w | rw) "rw">
13
+ ]>
14
+ <root>
15
+ <property name="readonly" access="r" />
16
+ <property name="readwrite" />
17
+ </root>
18
+ EOS
19
+ @doc = xp.parse
20
+ end
21
+
22
+ def teardown
23
+ @doc = nil
24
+ end
25
+
26
+ def test_attributes
27
+ # Get a element with an access attribute
28
+ elem = @doc.find_first('/root/property[@name="readonly"]')
29
+ assert_equal(2, elem.attributes.length)
30
+ refute_nil(elem['access'])
31
+
32
+ # Get a element node without a access attribute
33
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
34
+ assert_equal(1, elem.attributes.length)
35
+ assert_nil(elem['access'])
36
+ end
37
+
38
+ def test_attr
39
+ # Get a property node without a access attribute
40
+ elem = @doc.find_first('/root/property[@name="readonly"]')
41
+
42
+ # Get the attr_decl
43
+ attr = elem.attributes.get_attribute('access')
44
+ refute_nil(attr)
45
+ assert_equal(XML::Node::ATTRIBUTE_NODE, attr.node_type)
46
+ assert_equal('attribute', attr.node_type_name)
47
+
48
+ # Get its value
49
+ assert_equal('r', attr.value)
50
+ end
51
+
52
+ def test_attr_decl
53
+ # Get a property node without a access attribute
54
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
55
+
56
+ # Get the attr_decl
57
+ attr_decl = elem.attributes.get_attribute('access')
58
+ refute_nil(attr_decl)
59
+ assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
60
+ assert_equal('attribute declaration', attr_decl.node_type_name)
61
+
62
+ # Get its value
63
+ assert_equal('rw', attr_decl.value)
64
+ end
65
+
66
+ def test_type
67
+ # Get a property node without a access attribute
68
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
69
+ attr_decl = elem.attributes.get_attribute('access')
70
+
71
+ refute_nil(attr_decl)
72
+ assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
73
+ assert_equal('attribute declaration', attr_decl.node_type_name)
74
+ end
75
+
76
+ def test_name
77
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
78
+ attr_decl = elem.attributes.get_attribute('access')
79
+
80
+ assert_equal('access', attr_decl.name)
81
+ end
82
+
83
+ def test_value
84
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
85
+ attr_decl = elem.attributes.get_attribute('access')
86
+
87
+ assert_equal('rw', attr_decl.value)
88
+ end
89
+
90
+ def test_to_s
91
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
92
+ attr_decl = elem.attributes.get_attribute('access')
93
+
94
+ assert_equal('access = rw', attr_decl.to_s)
95
+ end
96
+
97
+ def test_prev
98
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
99
+ attr_decl = elem.attributes.get_attribute('access')
100
+
101
+ first_decl = attr_decl.prev
102
+ assert_equal(XML::Node::ATTRIBUTE_DECL, first_decl.node_type)
103
+ assert_equal('name', first_decl.name)
104
+ assert_nil(first_decl.value)
105
+
106
+ elem_decl = first_decl.prev
107
+ assert_equal(XML::Node::ELEMENT_DECL, elem_decl.node_type)
108
+ end
109
+
110
+ def test_next
111
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
112
+ attr_decl = elem.attributes.get_attribute('access')
113
+
114
+ next_decl = attr_decl.next
115
+ assert_nil(next_decl)
116
+ end
117
+
118
+ def test_doc
119
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
120
+ attr_decl = elem.attributes.get_attribute('access')
121
+
122
+ assert_same(@doc, attr_decl.doc)
123
+ end
124
+
125
+ def test_parent
126
+ elem = @doc.find_first('/root/property[@name="readwrite"]')
127
+ attr_decl = elem.attributes.get_attribute('access')
128
+
129
+ parent = attr_decl.parent
130
+ assert_instance_of(XML::Dtd, parent)
131
+ end
132
+ end
@@ -0,0 +1,142 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ class AttributesTest < Minitest::Test
6
+ def setup
7
+ xp = XML::Parser.string(<<-EOS)
8
+ <CityModel name="value"
9
+ xmlns="http://www.opengis.net/examples"
10
+ xmlns:city="http://www.opengis.net/examples"
11
+ xmlns:gml="http://www.opengis.net/gml"
12
+ xmlns:xlink="http://www.w3.org/1999/xlink"
13
+ xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
14
+ xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
15
+ <cityMember name="Cambridge"
16
+ xlink:type="simple"
17
+ xlink:title="Trinity Lane"
18
+ xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
19
+ gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
20
+ </CityModel>
21
+ EOS
22
+
23
+ @doc = xp.parse
24
+ end
25
+
26
+ def teardown
27
+ @doc = nil
28
+ end
29
+
30
+ def city_member
31
+ @doc.find('/city:CityModel/city:cityMember').first
32
+ end
33
+
34
+ def test_attributes
35
+ attributes = city_member.attributes
36
+ assert_instance_of(XML::Attributes, attributes)
37
+ assert_equal(5, attributes.length)
38
+ end
39
+
40
+ def test_each
41
+ attributes = city_member.attributes
42
+ length = attributes.inject(0) do |result, attr|
43
+ assert_instance_of(XML::Attr, attr)
44
+ result + 1
45
+ end
46
+ assert_equal(5, length)
47
+ end
48
+
49
+ def test_get_attribute
50
+ attributes = city_member.attributes
51
+
52
+ attr = attributes.get_attribute('name')
53
+ assert_instance_of(XML::Attr, attr)
54
+
55
+ attr = attributes.get_attribute('does_not_exist')
56
+ assert_nil(attr)
57
+
58
+ attr = attributes.get_attribute('name')
59
+ assert_instance_of(XML::Attr, attr)
60
+
61
+ attr = attributes.get_attribute('href')
62
+ assert_instance_of(XML::Attr, attr)
63
+ assert_instance_of(XML::Namespace, attr.ns)
64
+ assert_equal('xlink', attr.ns.prefix)
65
+ assert_equal('http://www.w3.org/1999/xlink', attr.ns.href)
66
+
67
+ attr = attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
68
+ assert_instance_of(XML::Attr, attr)
69
+
70
+ attr = attributes.get_attribute_ns('http://www.opengis.net/gml', 'remoteSchema')
71
+ assert_instance_of(XML::Attr, attr)
72
+
73
+ attr = attributes.get_attribute_ns('http://i.dont.exist', 'nor do i')
74
+ assert_nil(attr)
75
+ end
76
+
77
+ def test_property
78
+ attr = city_member.property('name')
79
+ assert_instance_of(String, attr)
80
+ assert_equal('Cambridge', attr)
81
+ end
82
+
83
+ def test_get_values
84
+ assert_equal('Cambridge', city_member[:name])
85
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', city_member[:href])
86
+
87
+ attributes = city_member.attributes
88
+ assert_equal('Cambridge', attributes[:name])
89
+ assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attributes[:href])
90
+ end
91
+
92
+ def test_get_values_gc
93
+ # There used to be a bug caused by accessing an
94
+ # attribute over and over and over again.
95
+ 20000.times do
96
+ @doc.root.attributes["key"]
97
+ end
98
+ end
99
+
100
+ def test_set_values
101
+ city_member[:name] = 'London'
102
+ assert_equal('London', city_member[:name])
103
+
104
+ city_member[:href] = 'foo'
105
+ assert_equal('foo', city_member[:href])
106
+
107
+ attributes = city_member.attributes
108
+
109
+ attributes[:name] = 'London'
110
+ assert_equal('London', attributes[:name])
111
+
112
+ attributes[:href] = 'foo'
113
+ assert_equal('foo', attributes[:href])
114
+ end
115
+
116
+ def test_str_sym()
117
+ attributes = city_member.attributes
118
+ assert_equal('Cambridge', attributes[:name])
119
+ assert_equal('Cambridge', attributes['name'])
120
+ end
121
+
122
+ def test_remove_first
123
+ attributes = @doc.find_first('/city:CityModel/city:cityMember').attributes
124
+ assert_equal(5, attributes.length)
125
+ attr = attributes.first
126
+ attr.remove!
127
+ assert_equal(4, attributes.length)
128
+ end
129
+
130
+ def test_remove_all
131
+ node = @doc.find_first('/city:CityModel/city:cityMember')
132
+ assert_equal(5, node.attributes.length)
133
+
134
+ attrs = Array.new
135
+ node.attributes.each do |attr|
136
+ attrs << attr
137
+ attr.remove!
138
+ end
139
+ assert_equal(5, attrs.length)
140
+ assert_equal(0, node.attributes.length)
141
+ end
142
+ end