nokogiri 1.3.3-x86-mingw32 → 1.4.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/CHANGELOG.ja.rdoc +48 -3
- data/CHANGELOG.rdoc +42 -0
- data/Manifest.txt +44 -29
- data/README.ja.rdoc +0 -2
- data/README.rdoc +4 -7
- data/Rakefile +14 -22
- data/bin/nokogiri +7 -5
- data/ext/nokogiri/extconf.rb +5 -21
- data/ext/nokogiri/html_document.c +14 -50
- data/ext/nokogiri/html_element_description.c +7 -7
- data/ext/nokogiri/html_entity_lookup.c +6 -4
- data/ext/nokogiri/html_sax_parser_context.c +92 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/nokogiri.c +9 -3
- data/ext/nokogiri/nokogiri.h +16 -20
- data/ext/nokogiri/xml_attr.c +1 -1
- data/ext/nokogiri/xml_attribute_decl.c +67 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +6 -5
- data/ext/nokogiri/xml_comment.c +3 -2
- data/ext/nokogiri/xml_document.c +93 -23
- data/ext/nokogiri/xml_document_fragment.c +1 -3
- data/ext/nokogiri/xml_dtd.c +63 -6
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_entity_decl.c +97 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_io.c +10 -3
- data/ext/nokogiri/xml_io.h +1 -0
- data/ext/nokogiri/xml_namespace.c +2 -2
- data/ext/nokogiri/xml_node.c +139 -34
- data/ext/nokogiri/xml_node.h +0 -1
- data/ext/nokogiri/xml_node_set.c +23 -16
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +78 -50
- data/ext/nokogiri/xml_sax_parser.c +109 -168
- data/ext/nokogiri/xml_sax_parser.h +33 -0
- data/ext/nokogiri/xml_sax_parser_context.c +155 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +11 -6
- data/ext/nokogiri/xml_syntax_error.c +63 -12
- data/ext/nokogiri/xml_text.c +4 -3
- data/ext/nokogiri/xml_xpath.c +1 -1
- data/ext/nokogiri/xml_xpath_context.c +12 -25
- data/ext/nokogiri/xslt_stylesheet.c +3 -3
- data/lib/nokogiri.rb +4 -4
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css/node.rb +1 -9
- data/lib/nokogiri/css/xpath_visitor.rb +11 -21
- data/lib/nokogiri/ffi/html/document.rb +0 -9
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +4 -2
- data/lib/nokogiri/ffi/libxml.rb +44 -10
- data/lib/nokogiri/ffi/structs/common_node.rb +1 -1
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +3 -1
- data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
- data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +4 -3
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +1 -1
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -0
- data/lib/nokogiri/ffi/xml/comment.rb +2 -2
- data/lib/nokogiri/ffi/xml/document.rb +29 -12
- data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -5
- data/lib/nokogiri/ffi/xml/dtd.rb +14 -3
- data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
- data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
- data/lib/nokogiri/ffi/xml/entity_decl.rb +27 -0
- data/lib/nokogiri/ffi/xml/node.rb +45 -5
- data/lib/nokogiri/ffi/xml/node_set.rb +1 -1
- data/lib/nokogiri/ffi/xml/reader.rb +45 -24
- data/lib/nokogiri/ffi/xml/sax/parser.rb +27 -34
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +67 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +5 -4
- data/lib/nokogiri/ffi/xml/syntax_error.rb +31 -16
- data/lib/nokogiri/ffi/xml/text.rb +2 -2
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/document.rb +39 -24
- data/lib/nokogiri/html/sax/parser.rb +2 -2
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml.rb +6 -1
- data/lib/nokogiri/xml/attr.rb +5 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +121 -13
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +43 -29
- data/lib/nokogiri/xml/document_fragment.rb +26 -6
- data/lib/nokogiri/xml/dtd.rb +5 -5
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +15 -0
- data/lib/nokogiri/xml/fragment_handler.rb +22 -11
- data/lib/nokogiri/xml/namespace.rb +6 -0
- data/lib/nokogiri/xml/node.rb +33 -15
- data/lib/nokogiri/xml/node_set.rb +66 -44
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/reader.rb +8 -0
- data/lib/nokogiri/xml/sax.rb +1 -1
- data/lib/nokogiri/xml/sax/document.rb +18 -1
- data/lib/nokogiri/xml/sax/parser.rb +15 -8
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +0 -3
- data/lib/nokogiri/xml/syntax_error.rb +4 -0
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/test/css/test_nthiness.rb +1 -1
- data/test/css/test_parser.rb +1 -1
- data/test/css/test_tokenizer.rb +1 -1
- data/test/css/test_xpath_visitor.rb +1 -1
- data/test/ffi/test_document.rb +1 -1
- data/test/files/shift_jis.html +10 -0
- data/test/files/staff.dtd +10 -0
- data/test/helper.rb +12 -3
- data/test/html/sax/test_parser.rb +1 -1
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +8 -2
- data/test/html/test_document.rb +23 -1
- data/test/html/test_document_encoding.rb +15 -1
- data/test/html/test_document_fragment.rb +10 -1
- data/test/html/test_element_description.rb +1 -2
- data/test/html/test_named_characters.rb +1 -1
- data/test/html/test_node.rb +61 -1
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +1 -3
- data/test/test_css_cache.rb +1 -1
- data/test/test_gc.rb +1 -1
- data/test/test_memory_leak.rb +1 -1
- data/test/test_nokogiri.rb +3 -3
- data/test/test_reader.rb +29 -1
- data/test/test_xslt_transforms.rb +1 -1
- data/test/xml/node/test_save_options.rb +1 -1
- data/test/xml/node/test_subclass.rb +1 -1
- data/test/xml/sax/test_parser.rb +64 -3
- data/test/xml/sax/test_parser_context.rb +56 -0
- data/test/xml/sax/test_push_parser.rb +11 -1
- data/test/xml/test_attr.rb +1 -1
- data/test/xml/test_attribute_decl.rb +82 -0
- data/test/xml/test_builder.rb +95 -1
- data/test/xml/test_cdata.rb +1 -1
- data/test/xml/test_comment.rb +7 -1
- data/test/xml/test_document.rb +147 -6
- data/test/xml/test_document_encoding.rb +1 -1
- data/test/xml/test_document_fragment.rb +55 -5
- data/test/xml/test_dtd.rb +40 -5
- data/test/xml/test_dtd_encoding.rb +3 -1
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +83 -0
- data/test/xml/test_entity_reference.rb +1 -1
- data/test/xml/test_namespace.rb +21 -1
- data/test/xml/test_node.rb +70 -4
- data/test/xml/test_node_attributes.rb +1 -1
- data/test/xml/test_node_encoding.rb +1 -1
- data/test/xml/test_node_set.rb +136 -2
- data/test/xml/test_parse_options.rb +1 -1
- data/test/xml/test_processing_instruction.rb +1 -1
- data/test/xml/test_reader_encoding.rb +1 -1
- data/test/xml/test_relax_ng.rb +1 -1
- data/test/xml/test_schema.rb +1 -1
- data/test/xml/test_syntax_error.rb +27 -0
- data/test/xml/test_text.rb +13 -1
- data/test/xml/test_unparented_node.rb +1 -1
- data/test/xml/test_xpath.rb +1 -1
- metadata +55 -38
- data/ext/nokogiri/html_sax_parser.c +0 -57
- data/ext/nokogiri/html_sax_parser.h +0 -11
- data/lib/action-nokogiri.rb +0 -38
- data/lib/nokogiri/decorators.rb +0 -2
- data/lib/nokogiri/decorators/hpricot.rb +0 -3
- data/lib/nokogiri/decorators/hpricot/node.rb +0 -56
- data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -54
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -30
- data/lib/nokogiri/ffi/html/sax/parser.rb +0 -21
- data/lib/nokogiri/hpricot.rb +0 -92
- data/lib/nokogiri/xml/entity_declaration.rb +0 -11
- data/lib/nokogiri/xml/sax/legacy_handlers.rb +0 -65
- data/test/hpricot/files/basic.xhtml +0 -17
- data/test/hpricot/files/boingboing.html +0 -2266
- data/test/hpricot/files/cy0.html +0 -3653
- data/test/hpricot/files/immob.html +0 -400
- data/test/hpricot/files/pace_application.html +0 -1320
- data/test/hpricot/files/tenderlove.html +0 -16
- data/test/hpricot/files/uswebgen.html +0 -220
- data/test/hpricot/files/utf8.html +0 -1054
- data/test/hpricot/files/week9.html +0 -1723
- data/test/hpricot/files/why.xml +0 -19
- data/test/hpricot/load_files.rb +0 -11
- data/test/hpricot/test_alter.rb +0 -68
- data/test/hpricot/test_builder.rb +0 -20
- data/test/hpricot/test_parser.rb +0 -350
- data/test/hpricot/test_paths.rb +0 -15
- data/test/hpricot/test_preserved.rb +0 -77
- data/test/hpricot/test_xml.rb +0 -30
@@ -19,7 +19,7 @@ module Nokogiri
|
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def |(node_set) # :nodoc:
|
23
23
|
raise(ArgumentError, "node_set must be a Nokogiri::XML::NodeSet") unless node_set.is_a?(XML::NodeSet)
|
24
24
|
new_set_ptr = LibXML::xmlXPathNodeSetMerge(nil, self.cstruct)
|
25
25
|
new_set_ptr = LibXML::xmlXPathNodeSetMerge(new_set_ptr, node_set.cstruct)
|
@@ -1,19 +1,20 @@
|
|
1
|
+
# :stopdoc:
|
1
2
|
module Nokogiri
|
2
3
|
module XML
|
3
4
|
class Reader
|
4
5
|
|
5
|
-
attr_accessor :cstruct
|
6
|
-
attr_accessor :reader_callback
|
6
|
+
attr_accessor :cstruct
|
7
|
+
attr_accessor :reader_callback
|
7
8
|
|
8
|
-
def default?
|
9
|
+
def default?
|
9
10
|
LibXML.xmlTextReaderIsDefault(cstruct) == 1
|
10
11
|
end
|
11
12
|
|
12
|
-
def value?
|
13
|
+
def value?
|
13
14
|
LibXML.xmlTextReaderHasValue(cstruct) == 1
|
14
15
|
end
|
15
16
|
|
16
|
-
def attributes?
|
17
|
+
def attributes?
|
17
18
|
# this implementation of xmlTextReaderHasAttributes explicitly includes
|
18
19
|
# namespaces and properties, because some earlier versions ignore
|
19
20
|
# namespaces.
|
@@ -23,7 +24,7 @@ module Nokogiri
|
|
23
24
|
node[:type] == Node::ELEMENT_NODE && (!node[:properties].null? || !node[:nsDef].null?)
|
24
25
|
end
|
25
26
|
|
26
|
-
def namespaces
|
27
|
+
def namespaces
|
27
28
|
return {} unless attributes?
|
28
29
|
|
29
30
|
ptr = LibXML.xmlTextReaderExpand(cstruct)
|
@@ -32,7 +33,7 @@ module Nokogiri
|
|
32
33
|
Reader.node_namespaces(ptr)
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
+
def attr_nodes
|
36
37
|
return {} unless attributes?
|
37
38
|
|
38
39
|
ptr = LibXML.xmlTextReaderExpand(cstruct)
|
@@ -42,7 +43,7 @@ module Nokogiri
|
|
42
43
|
Node.node_properties node_struct
|
43
44
|
end
|
44
45
|
|
45
|
-
def attribute_at(index)
|
46
|
+
def attribute_at(index)
|
46
47
|
return nil if index.nil?
|
47
48
|
index = index.to_i
|
48
49
|
attr_ptr = LibXML.xmlTextReaderGetAttributeNo(cstruct, index)
|
@@ -53,7 +54,7 @@ module Nokogiri
|
|
53
54
|
attr
|
54
55
|
end
|
55
56
|
|
56
|
-
def attribute(name)
|
57
|
+
def attribute(name)
|
57
58
|
return nil if name.nil?
|
58
59
|
attr_ptr = LibXML.xmlTextReaderGetAttribute(cstruct, name.to_s)
|
59
60
|
if attr_ptr.null?
|
@@ -81,56 +82,56 @@ module Nokogiri
|
|
81
82
|
attr
|
82
83
|
end
|
83
84
|
|
84
|
-
def attribute_count
|
85
|
+
def attribute_count
|
85
86
|
count = LibXML.xmlTextReaderAttributeCount(cstruct)
|
86
87
|
count == -1 ? nil : count
|
87
88
|
end
|
88
89
|
|
89
|
-
def depth
|
90
|
+
def depth
|
90
91
|
val = LibXML.xmlTextReaderDepth(cstruct)
|
91
92
|
val == -1 ? nil : val
|
92
93
|
end
|
93
94
|
|
94
|
-
def xml_version
|
95
|
+
def xml_version
|
95
96
|
val = LibXML.xmlTextReaderConstXmlVersion(cstruct)
|
96
97
|
val.null? ? nil : val.read_string
|
97
98
|
end
|
98
99
|
|
99
|
-
def lang
|
100
|
+
def lang
|
100
101
|
val = LibXML.xmlTextReaderConstXmlLang(cstruct)
|
101
102
|
val.null? ? nil : val.read_string
|
102
103
|
end
|
103
104
|
|
104
|
-
def value
|
105
|
+
def value
|
105
106
|
val = LibXML.xmlTextReaderConstValue(cstruct)
|
106
107
|
val.null? ? nil : val.read_string
|
107
108
|
end
|
108
109
|
|
109
|
-
def prefix
|
110
|
+
def prefix
|
110
111
|
val = LibXML.xmlTextReaderConstPrefix(cstruct)
|
111
112
|
val.null? ? nil : val.read_string
|
112
113
|
end
|
113
114
|
|
114
|
-
def namespace_uri
|
115
|
+
def namespace_uri
|
115
116
|
val = LibXML.xmlTextReaderConstNamespaceUri(cstruct)
|
116
117
|
val.null? ? nil : val.read_string
|
117
118
|
end
|
118
119
|
|
119
|
-
def local_name
|
120
|
+
def local_name
|
120
121
|
val = LibXML.xmlTextReaderConstLocalName(cstruct)
|
121
122
|
val.null? ? nil : val.read_string
|
122
123
|
end
|
123
124
|
|
124
|
-
def name
|
125
|
+
def name
|
125
126
|
val = LibXML.xmlTextReaderConstName(cstruct)
|
126
127
|
val.null? ? nil : val.read_string
|
127
128
|
end
|
128
129
|
|
129
|
-
def state
|
130
|
+
def state
|
130
131
|
LibXML.xmlTextReaderReadState(cstruct)
|
131
132
|
end
|
132
133
|
|
133
|
-
def read
|
134
|
+
def read
|
134
135
|
error_list = self.errors
|
135
136
|
|
136
137
|
LibXML.xmlSetStructuredErrorFunc(nil, SyntaxError.error_array_pusher(error_list))
|
@@ -150,7 +151,27 @@ module Nokogiri
|
|
150
151
|
nil
|
151
152
|
end
|
152
153
|
|
153
|
-
def
|
154
|
+
def inner_xml
|
155
|
+
string_ptr = LibXML.xmlTextReaderReadInnerXml(cstruct)
|
156
|
+
return nil if string_ptr.null?
|
157
|
+
string = string_ptr.read_string
|
158
|
+
LibXML.xmlFree(string_ptr)
|
159
|
+
string
|
160
|
+
end
|
161
|
+
|
162
|
+
def outer_xml
|
163
|
+
string_ptr = LibXML.xmlTextReaderReadOuterXml(cstruct)
|
164
|
+
return nil if string_ptr.null?
|
165
|
+
string = string_ptr.read_string
|
166
|
+
LibXML.xmlFree(string_ptr)
|
167
|
+
string
|
168
|
+
end
|
169
|
+
|
170
|
+
def node_type
|
171
|
+
LibXML.xmlTextReaderNodeType(cstruct)
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.from_memory(buffer, url=nil, encoding=nil, options=0)
|
154
175
|
raise(ArgumentError, "string cannot be nil") if buffer.nil?
|
155
176
|
|
156
177
|
memory = FFI::MemoryPointer.new(buffer.length) # we need to manage native memory lifecycle
|
@@ -164,7 +185,7 @@ module Nokogiri
|
|
164
185
|
reader
|
165
186
|
end
|
166
187
|
|
167
|
-
def self.from_io(io, url=nil, encoding=nil, options=0)
|
188
|
+
def self.from_io(io, url=nil, encoding=nil, options=0)
|
168
189
|
raise(ArgumentError, "io cannot be nil") if io.nil?
|
169
190
|
|
170
191
|
cb = IoCallbacks.reader(io) # we will keep a reference to prevent it from being GC'd
|
@@ -181,7 +202,7 @@ module Nokogiri
|
|
181
202
|
private
|
182
203
|
|
183
204
|
class << self
|
184
|
-
def node_namespaces(ptr)
|
205
|
+
def node_namespaces(ptr)
|
185
206
|
cstruct = LibXML::XmlNode.new(ptr)
|
186
207
|
ahash = {}
|
187
208
|
return ahash unless cstruct[:type] == Node::ELEMENT_NODE
|
@@ -200,7 +221,7 @@ module Nokogiri
|
|
200
221
|
ahash
|
201
222
|
end
|
202
223
|
end
|
203
|
-
|
204
224
|
end
|
205
225
|
end
|
206
226
|
end
|
227
|
+
# :startdoc:
|
@@ -2,38 +2,23 @@ module Nokogiri
|
|
2
2
|
module XML
|
3
3
|
module SAX
|
4
4
|
class Parser
|
5
|
+
# :stopdoc:
|
5
6
|
|
6
|
-
attr_accessor :cstruct
|
7
|
+
attr_accessor :cstruct
|
7
8
|
|
8
|
-
def
|
9
|
-
raise(ArgumentError, 'data cannot be nil') if data.nil?
|
10
|
-
LibXML.xmlSAXUserParseMemory(cstruct, nil, data, data.length)
|
11
|
-
data
|
12
|
-
end
|
13
|
-
|
14
|
-
def native_parse_io(io, encoding) # :nodoc:
|
15
|
-
sax_ctx = LibXML.xmlCreateIOParserCtxt(cstruct, nil, IoCallbacks.reader(io), nil, nil, encoding)
|
16
|
-
LibXML.xmlParseDocument(sax_ctx)
|
17
|
-
LibXML.xmlFreeParserCtxt(sax_ctx)
|
18
|
-
io
|
19
|
-
end
|
20
|
-
|
21
|
-
def native_parse_file(data) # :nodoc:
|
22
|
-
LibXML.xmlSAXUserParseFile(cstruct, nil, data)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.new(doc = XML::SAX::Document.new, encoding = 'ASCII') # :nodoc:
|
9
|
+
def self.new(doc = XML::SAX::Document.new, encoding = 'UTF-8')
|
26
10
|
parser = allocate
|
27
11
|
parser.document = doc
|
28
12
|
parser.encoding = encoding
|
29
13
|
parser.cstruct = LibXML::XmlSaxHandler.allocate
|
30
14
|
parser.send(:setup_lambdas)
|
15
|
+
parser.instance_variable_set(:@ctxt, nil)
|
31
16
|
parser
|
32
17
|
end
|
33
18
|
|
34
|
-
|
19
|
+
private
|
35
20
|
|
36
|
-
def setup_lambdas
|
21
|
+
def setup_lambdas
|
37
22
|
@closures = {} # we need to keep references to the closures to avoid GC
|
38
23
|
|
39
24
|
[ :startDocument, :endDocument, :startElement, :endElement, :characters,
|
@@ -46,15 +31,23 @@ module Nokogiri
|
|
46
31
|
cstruct[:initialized] = Nokogiri::LibXML::XmlSaxHandler::XML_SAX2_MAGIC
|
47
32
|
end
|
48
33
|
|
49
|
-
def __internal__startDocument(_)
|
34
|
+
def __internal__startDocument(_)
|
35
|
+
if @ctxt && @ctxt[:html] == 0 && @ctxt[:standalone] != -1
|
36
|
+
standalone = {
|
37
|
+
0 => 'no',
|
38
|
+
1 => 'yes',
|
39
|
+
}[@ctxt[:standalone]]
|
40
|
+
|
41
|
+
@document.xmldecl @ctxt[:version], @ctxt[:encoding], standalone
|
42
|
+
end
|
50
43
|
@document.start_document
|
51
44
|
end
|
52
45
|
|
53
|
-
def __internal__endDocument(_)
|
46
|
+
def __internal__endDocument(_)
|
54
47
|
@document.end_document
|
55
48
|
end
|
56
49
|
|
57
|
-
def __internal__startElement(_, name, attributes)
|
50
|
+
def __internal__startElement(_, name, attributes)
|
58
51
|
attrs = []
|
59
52
|
unless attributes.null?
|
60
53
|
j = 0
|
@@ -66,33 +59,33 @@ module Nokogiri
|
|
66
59
|
@document.start_element name, attrs
|
67
60
|
end
|
68
61
|
|
69
|
-
def __internal__endElement(_, name)
|
62
|
+
def __internal__endElement(_, name)
|
70
63
|
@document.end_element name
|
71
64
|
end
|
72
65
|
|
73
|
-
def __internal__characters(_, data, data_length)
|
66
|
+
def __internal__characters(_, data, data_length)
|
74
67
|
@document.characters data.slice(0, data_length)
|
75
68
|
end
|
76
69
|
|
77
|
-
def __internal__comment(_, data)
|
70
|
+
def __internal__comment(_, data)
|
78
71
|
@document.comment data
|
79
72
|
end
|
80
73
|
|
81
|
-
def __internal__warning(_, msg)
|
74
|
+
def __internal__warning(_, msg)
|
82
75
|
# TODO: vasprintf here
|
83
76
|
@document.warning(msg)
|
84
77
|
end
|
85
78
|
|
86
|
-
def __internal__error(_, msg)
|
79
|
+
def __internal__error(_, msg)
|
87
80
|
# TODO: vasprintf here
|
88
81
|
@document.error(msg)
|
89
82
|
end
|
90
83
|
|
91
|
-
def __internal__cdataBlock(_, data, data_length)
|
84
|
+
def __internal__cdataBlock(_, data, data_length)
|
92
85
|
@document.cdata_block data.slice(0, data_length)
|
93
86
|
end
|
94
87
|
|
95
|
-
def __internal__startElementNs(_, localname, prefix, uri, nb_namespaces, namespaces, nb_attributes, nb_defaulted, attributes)
|
88
|
+
def __internal__startElementNs(_, localname, prefix, uri, nb_namespaces, namespaces, nb_attributes, nb_defaulted, attributes)
|
96
89
|
localname = localname.null? ? nil : localname.read_string
|
97
90
|
prefix = prefix .null? ? nil : prefix .read_string
|
98
91
|
uri = uri .null? ? nil : uri .read_string
|
@@ -132,17 +125,17 @@ module Nokogiri
|
|
132
125
|
uri,
|
133
126
|
ns_list
|
134
127
|
)
|
135
|
-
start_element_namespace(localname, attr_list, prefix, uri, ns_list)
|
136
128
|
end
|
137
129
|
|
138
|
-
def __internal__endElementNs(_, localname, prefix, uri)
|
130
|
+
def __internal__endElementNs(_, localname, prefix, uri)
|
139
131
|
localname = localname.null? ? nil : localname.read_string
|
140
132
|
prefix = prefix .null? ? nil : prefix .read_string
|
141
133
|
uri = uri .null? ? nil : uri .read_string
|
142
134
|
|
143
135
|
@document.end_element_namespace(localname, prefix, uri)
|
144
|
-
end_element_namespace(localname, prefix, uri)
|
145
136
|
end
|
137
|
+
|
138
|
+
# :startdoc:
|
146
139
|
end
|
147
140
|
end
|
148
141
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
module SAX
|
5
|
+
class ParserContext
|
6
|
+
attr_accessor :cstruct
|
7
|
+
attr_accessor :reader_callback
|
8
|
+
|
9
|
+
def self.memory data
|
10
|
+
raise(ArgumentError, 'data cannot be nil') if data.nil?
|
11
|
+
raise('data cannot be empty') if data.length == 0
|
12
|
+
ctx = LibXML::XmlParserContext.new(
|
13
|
+
LibXML.xmlCreateMemoryParserCtxt data, data.length
|
14
|
+
)
|
15
|
+
pc = allocate
|
16
|
+
pc.cstruct = ctx
|
17
|
+
pc
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.io io, encoding
|
21
|
+
reader_callback = IoCallbacks.reader(io) # keep a reference to prevent it from being GC'd
|
22
|
+
sax_ctx = LibXML.xmlCreateIOParserCtxt(
|
23
|
+
nil,
|
24
|
+
nil,
|
25
|
+
reader_callback,
|
26
|
+
nil,
|
27
|
+
nil,
|
28
|
+
encoding
|
29
|
+
)
|
30
|
+
pc = allocate
|
31
|
+
pc.cstruct = LibXML::XmlParserContext.new sax_ctx
|
32
|
+
pc.reader_callback = reader_callback
|
33
|
+
pc
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.file filename
|
37
|
+
ctx = LibXML.xmlCreateFileParserCtxt filename
|
38
|
+
pc = allocate
|
39
|
+
pc.cstruct = LibXML::XmlParserContext.new ctx
|
40
|
+
pc
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_with sax_handler, type = :xml
|
44
|
+
raise ArgumentError unless XML::SAX::Parser === sax_handler
|
45
|
+
sax = sax_handler.cstruct
|
46
|
+
cstruct[:sax] = sax
|
47
|
+
|
48
|
+
sax_handler.instance_variable_set(:@ctxt, cstruct)
|
49
|
+
|
50
|
+
LibXML.send(:"#{type}ParseDocument", cstruct)
|
51
|
+
|
52
|
+
cstruct[:sax] = nil
|
53
|
+
LibXML.xmlFreeDoc cstruct[:myDoc] unless cstruct[:myDoc].null?
|
54
|
+
end
|
55
|
+
|
56
|
+
def replace_entities=(value)
|
57
|
+
self.cstruct[:replaceEntities] = value ? 1 : 0
|
58
|
+
end
|
59
|
+
|
60
|
+
def replace_entities
|
61
|
+
self.cstruct[:replaceEntities] == 0 ? false : true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
# :startdoc:
|
@@ -14,10 +14,11 @@ module Nokogiri
|
|
14
14
|
size = chunk.length
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
rcode = LibXML.xmlParseChunk(cstruct, chunk, size, last_chunk ? 1 : 0)
|
18
|
+
if rcode != 0
|
19
|
+
error = LibXML.xmlCtxtGetLastError(cstruct)
|
20
|
+
raise Nokogiri::XML::SyntaxError.wrap(error)
|
21
|
+
end
|
21
22
|
|
22
23
|
self
|
23
24
|
end
|
@@ -1,70 +1,84 @@
|
|
1
|
+
# :stopdoc:
|
1
2
|
module Nokogiri
|
2
3
|
module XML
|
3
4
|
class SyntaxError < ::Nokogiri::SyntaxError
|
4
5
|
|
5
|
-
attr_accessor :cstruct
|
6
|
+
attr_accessor :cstruct
|
6
7
|
|
7
|
-
def
|
8
|
+
def initialize(message)
|
9
|
+
self.cstruct = LibXML::XmlSyntaxError.new(LibXML::XmlSyntaxError.allocate())
|
10
|
+
self.cstruct[:message] = FFI::MemoryPointer.from_string(message)
|
11
|
+
end
|
12
|
+
|
13
|
+
def domain
|
8
14
|
cstruct[:domain]
|
9
15
|
end
|
10
16
|
|
11
|
-
def code
|
17
|
+
def code
|
12
18
|
cstruct[:code]
|
13
19
|
end
|
14
20
|
|
15
|
-
def message
|
16
|
-
cstruct[:message]
|
21
|
+
def message
|
22
|
+
val = cstruct[:message]
|
23
|
+
val.null? ? nil : val.read_string
|
17
24
|
end
|
18
25
|
undef_method :inspect
|
19
26
|
alias_method :inspect, :message
|
20
27
|
undef_method :to_s
|
21
28
|
alias_method :to_s, :message
|
22
29
|
|
23
|
-
def
|
30
|
+
def message=(string)
|
31
|
+
unless cstruct[:message].null?
|
32
|
+
LibXML.xmlFree(cstruct[:message])
|
33
|
+
end
|
34
|
+
cstruct[:message] = string
|
35
|
+
end
|
36
|
+
|
37
|
+
def level
|
24
38
|
cstruct[:level]
|
25
39
|
end
|
26
40
|
|
27
|
-
def file
|
41
|
+
def file
|
28
42
|
cstruct[:file].null? ? nil : cstruct[:file]
|
29
43
|
end
|
30
44
|
|
31
|
-
def line
|
45
|
+
def line
|
32
46
|
cstruct[:line]
|
33
47
|
end
|
34
48
|
|
35
|
-
def str1
|
49
|
+
def str1
|
36
50
|
cstruct[:str1].null? ? nil : cstruct[:str1]
|
37
51
|
end
|
38
52
|
|
39
|
-
def str2
|
53
|
+
def str2
|
40
54
|
cstruct[:str].null? ? nil : cstruct[:str]
|
41
55
|
end
|
42
56
|
|
43
|
-
def str3
|
57
|
+
def str3
|
44
58
|
cstruct[:str3].null? ? nil : cstruct[:str3]
|
45
59
|
end
|
46
60
|
|
47
|
-
def int1
|
61
|
+
def int1
|
48
62
|
cstruct[:int1]
|
49
63
|
end
|
50
64
|
|
51
|
-
def column
|
65
|
+
def column
|
52
66
|
cstruct[:int2]
|
53
67
|
end
|
54
68
|
alias_method :int2, :column
|
55
69
|
|
56
70
|
class << self
|
57
|
-
def error_array_pusher(array)
|
71
|
+
def error_array_pusher(array)
|
58
72
|
Proc.new do |_ignored_, error|
|
59
73
|
array << wrap(error) if array
|
60
74
|
end
|
61
75
|
end
|
62
76
|
|
63
|
-
def wrap(error_ptr)
|
77
|
+
def wrap(error_ptr)
|
64
78
|
error_struct = LibXML::XmlSyntaxError.allocate
|
65
79
|
LibXML.xmlCopyError(error_ptr, error_struct)
|
66
80
|
error_cstruct = LibXML::XmlSyntaxError.new(error_struct)
|
67
|
-
error = self.
|
81
|
+
error = self.allocate # will generate XML::XPath::SyntaxError or XML::SyntaxError
|
68
82
|
error.cstruct = error_cstruct
|
69
83
|
error
|
70
84
|
end
|
@@ -74,3 +88,4 @@ module Nokogiri
|
|
74
88
|
end
|
75
89
|
|
76
90
|
end
|
91
|
+
# :startdoc:
|