libxml-ruby 3.2.0 → 3.2.3
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.
- checksums.yaml +4 -4
- data/HISTORY +23 -1
- data/README.rdoc +52 -36
- data/Rakefile +24 -16
- data/ext/libxml/ruby_xml.c +4 -0
- data/ext/libxml/ruby_xml_document.c +0 -4
- data/ext/libxml/ruby_xml_encoding.c +1 -13
- data/ext/libxml/ruby_xml_encoding.h +0 -3
- data/ext/libxml/ruby_xml_io.c +14 -18
- data/ext/libxml/ruby_xml_io.h +1 -1
- data/ext/libxml/ruby_xml_namespace.c +1 -0
- data/ext/libxml/ruby_xml_node.c +8 -4
- data/ext/libxml/ruby_xml_schema.c +151 -79
- data/ext/libxml/ruby_xml_schema.h +2 -5
- data/ext/libxml/ruby_xml_schema_attribute.c +23 -71
- data/ext/libxml/ruby_xml_schema_element.c +28 -54
- data/ext/libxml/ruby_xml_schema_facet.c +15 -21
- data/ext/libxml/ruby_xml_schema_type.c +19 -37
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +189 -192
- data/libxml-ruby.gemspec +1 -1
- data/test/model/shiporder.rnc +2 -2
- data/test/model/shiporder.rng +2 -2
- data/test/model/shiporder.xsd +7 -3
- data/test/model/shiporder_bad.xsd +40 -0
- data/test/model/shiporder_import.xsd +45 -0
- data/test/test_document.rb +111 -110
- data/test/test_dtd.rb +2 -1
- data/test/test_helper.rb +2 -0
- data/test/test_parser.rb +1 -1
- data/test/test_parser_context.rb +3 -9
- data/test/test_reader.rb +2 -1
- data/test/test_sax_parser.rb +13 -6
- data/test/test_schema.rb +92 -29
- data/test/test_writer.rb +48 -25
- data/test/test_xml.rb +2 -1
- metadata +11 -10
- data/ext/libxml/extconf.h +0 -3
data/test/model/shiporder.rnc
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
#
|
6
6
|
namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"
|
7
7
|
|
8
|
-
start =
|
8
|
+
start = shiporderType
|
9
9
|
|
10
|
-
|
10
|
+
shiporderType = element shiporder { attribute orderid { text },
|
11
11
|
attribute xsi:noNamespaceSchemaLocation { text },
|
12
12
|
orderperson, shipto, item* }
|
13
13
|
|
data/test/model/shiporder.rng
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
-->
|
8
8
|
<grammar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://relaxng.org/ns/structure/1.0">
|
9
9
|
<start>
|
10
|
-
<ref name="
|
10
|
+
<ref name="shiporderType"/>
|
11
11
|
</start>
|
12
|
-
<define name="
|
12
|
+
<define name="shiporderType">
|
13
13
|
<element name="shiporder">
|
14
14
|
<attribute name="orderid"/>
|
15
15
|
<attribute name="xsi:noNamespaceSchemaLocation"/>
|
data/test/model/shiporder.xsd
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
<?xml version="1.0" encoding="iso-8859-1" ?>
|
2
2
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
3
|
-
<xs:element name="shiporder" type="shiporder"/>
|
4
3
|
|
5
|
-
<xs:
|
4
|
+
<xs:import namespace="http://xml4r.org/ibxml-ruby/test/shiporder"
|
5
|
+
schemaLocation="shiporder_import.xsd"/>
|
6
|
+
|
7
|
+
<xs:element name="shiporder" type="shiporderType"/>
|
8
|
+
|
9
|
+
<xs:complexType name="shiporderType">
|
6
10
|
<xs:annotation>
|
7
11
|
<xs:documentation>Shiporder type documentation</xs:documentation>
|
8
12
|
</xs:annotation>
|
@@ -37,4 +41,4 @@
|
|
37
41
|
<xs:attribute name="foo" default="1" type="xs:integer" use="optional"/>
|
38
42
|
<xs:attribute name="bar" use="prohibited"/>
|
39
43
|
</xs:complexType>
|
40
|
-
</xs:schema>
|
44
|
+
</xs:schema>
|
@@ -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="shiporderType"/>
|
4
|
+
|
5
|
+
<xs:complexType name="shiporderType">
|
6
|
+
<xs:anntation>
|
7
|
+
<xs:documentation>Shiporder type documentation</xs:documentation>
|
8
|
+
</xs:anntation>
|
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:seq>
|
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:seq>
|
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,45 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1" ?>
|
2
|
+
<xs:schema xmlns="http://xml4r.org/libxml-ruby/test/shiporder"
|
3
|
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
4
|
+
targetNamespace="http://xml4r.org/libxml-ruby/test/shiporder">
|
5
|
+
|
6
|
+
<xs:element name="shiporder" type="shiporderFooType"/>
|
7
|
+
<xs:complexType name="shiporderFooType">
|
8
|
+
<xs:annotation>
|
9
|
+
<xs:documentation>Shiporder type documentation for Testing of imported schema</xs:documentation>
|
10
|
+
</xs:annotation>
|
11
|
+
<xs:sequence>
|
12
|
+
<xs:element name="orderperson" type="xs:string">
|
13
|
+
<xs:annotation>
|
14
|
+
<xs:documentation>orderperson element documentation</xs:documentation>
|
15
|
+
</xs:annotation>
|
16
|
+
</xs:element>
|
17
|
+
<xs:element name="shipto">
|
18
|
+
<xs:complexType>
|
19
|
+
<xs:sequence>
|
20
|
+
<xs:element name="name" type="xs:string"/>
|
21
|
+
<xs:element name="address" type="xs:string"/>
|
22
|
+
<xs:element name="city" type="xs:string"/>
|
23
|
+
<xs:element name="country" type="xs:string"/>
|
24
|
+
<xs:element name="phone" type="xs:string"/>
|
25
|
+
</xs:sequence>
|
26
|
+
</xs:complexType>
|
27
|
+
</xs:element>
|
28
|
+
<xs:element name="item" maxOccurs="unbounded">
|
29
|
+
<xs:complexType>
|
30
|
+
<xs:sequence>
|
31
|
+
<xs:element name="title" type="xs:string"/>
|
32
|
+
<xs:element name="note" type="xs:string" minOccurs="0"/>
|
33
|
+
<xs:element name="quantity" type="xs:positiveInteger"/>
|
34
|
+
<xs:element name="price" type="xs:decimal"/>
|
35
|
+
<xs:element name="discount" type="xs:decimal"/>
|
36
|
+
</xs:sequence>
|
37
|
+
</xs:complexType>
|
38
|
+
</xs:element>
|
39
|
+
</xs:sequence>
|
40
|
+
<xs:attribute name="orderid" type="xs:string" use="required"/>
|
41
|
+
<xs:attribute name="foo" default="1" type="xs:integer" use="optional"/>
|
42
|
+
<xs:attribute name="bar" type="xs:string" use="optional"/>
|
43
|
+
<xs:attribute name="xyzzy" type="xs:string" use="prohibited"/>
|
44
|
+
</xs:complexType>
|
45
|
+
</xs:schema>
|
data/test/test_document.rb
CHANGED
@@ -13,119 +13,120 @@ class TestDocument < Minitest::Test
|
|
13
13
|
@doc = nil
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
16
|
+
def test_klass
|
17
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_context
|
21
|
+
context = @doc.context
|
22
|
+
assert_instance_of(LibXML::XML::XPath::Context, context)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find
|
26
|
+
set = @doc.find('/ruby_array/fixnum')
|
27
|
+
assert_instance_of(LibXML::XML::XPath::Object, set)
|
28
|
+
assert_raises(NoMethodError) {
|
29
|
+
set.xpath
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_compression
|
34
|
+
if LibXML::XML.enabled_zlib?
|
35
|
+
0.upto(9) do |i|
|
36
|
+
assert_equal(i, @doc.compression = i)
|
37
|
+
assert_equal(i, @doc.compression)
|
38
|
+
end
|
39
|
+
|
40
|
+
9.downto(0) do |i|
|
41
|
+
assert_equal(i, @doc.compression = i)
|
42
|
+
assert_equal(i, @doc.compression)
|
43
|
+
end
|
44
|
+
|
45
|
+
10.upto(20) do |i|
|
46
|
+
# assert_equal(9, @doc.compression = i)
|
47
|
+
assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
|
48
|
+
assert_equal(9, @doc.compression)
|
49
|
+
end
|
50
|
+
|
51
|
+
-1.downto(-10) do |i|
|
52
|
+
# assert_equal(0, @doc.compression = i)
|
53
|
+
assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
|
54
|
+
assert_equal(0, @doc.compression)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_version
|
60
|
+
assert_equal('1.0', @doc.version)
|
61
|
+
|
62
|
+
doc = LibXML::XML::Document.new('6.9')
|
63
|
+
assert_equal('6.9', doc.version)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_write_root
|
67
|
+
@doc.root = LibXML::XML::Node.new('rubynet')
|
68
|
+
assert_instance_of(LibXML::XML::Node, @doc.root)
|
69
|
+
assert_instance_of(LibXML::XML::Document, @doc.root.doc)
|
70
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
|
71
|
+
@doc.to_s(:indent => false))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_doc_node_type
|
75
|
+
assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_doc_node_type_name
|
79
|
+
assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_xhtml
|
83
|
+
doc = LibXML::XML::Document.new
|
84
|
+
assert(!doc.xhtml?)
|
85
|
+
LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
|
86
|
+
assert(doc.xhtml?)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_document_root
|
90
|
+
doc1 = LibXML::XML::Document.string("<one/>")
|
91
|
+
doc2 = LibXML::XML::Document.string("<two/>")
|
92
|
+
|
93
|
+
error = assert_raises(LibXML::XML::Error) do
|
94
|
+
doc1.root = doc2.root
|
95
|
+
end
|
96
|
+
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
|
97
|
+
error.to_s)
|
98
|
+
|
99
|
+
doc2.root << doc2.import(doc1.root)
|
100
|
+
assert_equal('<one/>', doc1.root.to_s)
|
101
|
+
assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
|
102
|
+
|
103
|
+
assert(!doc1.root.equal?(doc2.root))
|
104
|
+
assert(doc1.root.doc != doc2.root.doc)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_import_node
|
108
|
+
doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
|
109
|
+
doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
|
110
|
+
|
111
|
+
node = doc1.root.child
|
112
|
+
|
113
|
+
error = assert_raises(LibXML::XML::Error) do
|
114
|
+
doc2.root << node
|
115
|
+
end
|
116
|
+
|
117
|
+
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
|
118
|
+
error.to_s)
|
119
|
+
|
120
|
+
doc2.root << doc2.import(node)
|
121
|
+
|
122
|
+
assert_equal("<nums><two/><one/></nums>",
|
123
|
+
doc2.root.to_s(:indent => false))
|
124
|
+
end
|
125
125
|
|
126
126
|
def test_nonet
|
127
127
|
xml_string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
128
128
|
xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
|
129
|
-
|
129
|
+
file = File.join(File.dirname(__FILE__), 'model/atom.xml')
|
130
|
+
schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
|
130
131
|
end
|
131
132
|
end
|
data/test/test_dtd.rb
CHANGED
@@ -84,7 +84,8 @@ class TestDtd < Minitest::Test
|
|
84
84
|
assert_nil(error.file)
|
85
85
|
assert_nil(error.line)
|
86
86
|
assert_equal('invalid', error.str1)
|
87
|
-
|
87
|
+
# Different answers across operating systems
|
88
|
+
# assert_nil(error.str2)
|
88
89
|
assert_nil(error.str3)
|
89
90
|
assert_equal(0, error.int1)
|
90
91
|
assert_equal(0, error.int2)
|
data/test/test_helper.rb
CHANGED
data/test/test_parser.rb
CHANGED
data/test/test_parser_context.rb
CHANGED
@@ -127,18 +127,12 @@ class TestParserContext < Minitest::Test
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
if ENV['NOTWORKING']
|
131
|
-
def test_num_chars
|
132
|
-
assert_equal(17, context.num_chars)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
130
|
def test_replace_entities
|
137
131
|
context = LibXML::XML::Parser::Context.new
|
138
132
|
assert(!context.replace_entities?)
|
139
133
|
|
140
|
-
|
141
|
-
|
134
|
+
context.options = LibXML::XML::Parser::Options::NOENT
|
135
|
+
assert(context.replace_entities?)
|
142
136
|
|
143
137
|
context.options = 0
|
144
138
|
assert(!context.replace_entities?)
|
@@ -185,7 +179,7 @@ class TestParserContext < Minitest::Test
|
|
185
179
|
assert_nil(context.name_node)
|
186
180
|
assert_equal(0, context.name_depth)
|
187
181
|
assert_equal(10, context.name_depth_max)
|
188
|
-
|
182
|
+
assert([0, 17].include?(context.num_chars))
|
189
183
|
assert_equal(false, context.replace_entities?)
|
190
184
|
assert_equal(1, context.space_depth)
|
191
185
|
assert_equal(10, context.space_depth_max)
|
data/test/test_reader.rb
CHANGED
@@ -249,9 +249,10 @@ class TestReader < Minitest::Test
|
|
249
249
|
end
|
250
250
|
|
251
251
|
def test_bytes_consumed
|
252
|
+
ending_are_rn = File.binread(XML_FILE).include? "\r\n"
|
252
253
|
reader = LibXML::XML::Reader.file(XML_FILE)
|
253
254
|
reader.read
|
254
|
-
assert_equal(428, reader.byte_consumed)
|
255
|
+
assert_equal(ending_are_rn ? 428 : 416, reader.byte_consumed)
|
255
256
|
end
|
256
257
|
|
257
258
|
def test_node
|
data/test/test_sax_parser.rb
CHANGED
@@ -181,7 +181,7 @@ class TestSaxParser < Minitest::Test
|
|
181
181
|
xml = File.read(saxtest_file)
|
182
182
|
io = StringIO.new(xml)
|
183
183
|
parser = LibXML::XML::SaxParser.io(io)
|
184
|
-
|
184
|
+
|
185
185
|
parser.callbacks = TestCaseCallbacks.new
|
186
186
|
parser.parse
|
187
187
|
verify(parser)
|
@@ -250,25 +250,32 @@ EOS
|
|
250
250
|
result = parser.callbacks.result
|
251
251
|
|
252
252
|
i = -1
|
253
|
+
|
254
|
+
base_err_msg = "Fatal error: (Premature end of data in tag Results line 1|EndTag: '<\\/' not found) at :2\\."
|
255
|
+
re_err_msg1 = /\A(error: )#{base_err_msg}\z/
|
256
|
+
re_err_msg2 = /\A#{base_err_msg}\z/
|
257
|
+
|
253
258
|
assert_equal("startdoc", result[i+=1])
|
254
259
|
assert_equal("start_element: Results, attr: {}", result[i+=1])
|
255
260
|
assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
|
256
261
|
assert_equal("characters: \n", result[i+=1])
|
257
|
-
|
262
|
+
assert_match(re_err_msg1, result[i+=1])
|
258
263
|
assert_equal("end_document", result[i+=1])
|
259
264
|
|
260
265
|
refute_nil(error)
|
261
266
|
assert_kind_of(LibXML::XML::Error, error)
|
262
|
-
|
267
|
+
assert_match(re_err_msg2, error.message)
|
263
268
|
assert_equal(LibXML::XML::Error::PARSER, error.domain)
|
264
|
-
|
269
|
+
|
270
|
+
assert([LibXML::XML::Error::TAG_NOT_FINISHED, LibXML::XML::Error::LTSLASH_REQUIRED].include?(error.code))
|
265
271
|
assert_equal(LibXML::XML::Error::FATAL, error.level)
|
266
272
|
assert_nil(error.file)
|
267
273
|
assert_equal(2, error.line)
|
268
|
-
|
274
|
+
# Sometimes this is nil and sometimes its not depending on OS and libxlm version
|
275
|
+
# assert_nil(error.str1)
|
269
276
|
assert_nil(error.str2)
|
270
277
|
assert_nil(error.str3)
|
271
|
-
|
278
|
+
assert([0, 1].include?(error.int1))
|
272
279
|
assert_equal(1, error.int2)
|
273
280
|
assert_nil(error.node)
|
274
281
|
end
|