nokogiri 1.3.3-x86-mswin32 → 1.4.0-x86-mswin32
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
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
# :stopdoc:
|
3
|
+
module LibXML
|
4
|
+
class XmlParserContext < FFI::Struct
|
5
|
+
layout(
|
6
|
+
:sax, :pointer,
|
7
|
+
:userData, :pointer,
|
8
|
+
:myDoc, :pointer,
|
9
|
+
:wellFormed, :int,
|
10
|
+
:replaceEntities, :int,
|
11
|
+
:version, :string,
|
12
|
+
:encoding, :string,
|
13
|
+
:standalone, :int,
|
14
|
+
:html, :int
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
# :startdoc:
|
19
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Nokogiri
|
2
|
-
|
3
|
-
|
4
|
-
class XmlSaxPushParserContext < FFI::ManagedStruct
|
2
|
+
# :stopdoc:
|
3
|
+
module LibXML
|
4
|
+
class XmlSaxPushParserContext < FFI::ManagedStruct
|
5
5
|
|
6
6
|
layout :dummy, :int, 0 # to avoid @layout warnings
|
7
7
|
|
@@ -11,4 +11,5 @@ module Nokogiri
|
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
14
|
+
# :startdoc:
|
14
15
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
# :stopdoc:
|
4
|
+
class AttributeDecl < Nokogiri::XML::Node
|
5
|
+
def enumeration
|
6
|
+
list = []
|
7
|
+
return list if cstruct[:tree].null?
|
8
|
+
head = LibXML::XmlEnumeration.new cstruct[:tree]
|
9
|
+
loop do
|
10
|
+
list << head[:name]
|
11
|
+
break if head[:next].null?
|
12
|
+
head = LibXML::XmlEnumeration.new head[:next]
|
13
|
+
end
|
14
|
+
list
|
15
|
+
end
|
16
|
+
|
17
|
+
def attribute_type
|
18
|
+
cstruct[:atype]
|
19
|
+
end
|
20
|
+
|
21
|
+
def default
|
22
|
+
cstruct[:default_value]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# :startdoc:
|
26
|
+
end
|
27
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
|
+
# :stopdoc:
|
1
2
|
module Nokogiri
|
2
3
|
module XML
|
3
4
|
class Document < Node
|
4
5
|
|
5
|
-
attr_accessor :cstruct
|
6
|
+
attr_accessor :cstruct
|
6
7
|
|
7
|
-
def url
|
8
|
+
def url
|
8
9
|
cstruct[:URL]
|
9
10
|
end
|
10
11
|
|
11
|
-
def root=
|
12
|
+
def root= new_root
|
12
13
|
old_root = nil
|
13
14
|
if new_root.cstruct[:doc] != cstruct[:doc]
|
14
15
|
old_root_ptr = LibXML.xmlDocGetRootElement(cstruct)
|
@@ -23,34 +24,38 @@ module Nokogiri
|
|
23
24
|
new_root
|
24
25
|
end
|
25
26
|
|
26
|
-
def root
|
27
|
+
def root
|
27
28
|
ptr = LibXML.xmlDocGetRootElement(cstruct)
|
28
29
|
ptr.null? ? nil : Node.wrap(LibXML::XmlNode.new(ptr))
|
29
30
|
end
|
30
31
|
|
31
|
-
def encoding=
|
32
|
+
def encoding= encoding
|
32
33
|
# TODO: if :encoding is already set, then it's probably getting leaked.
|
33
34
|
cstruct[:encoding] = LibXML.xmlStrdup(encoding)
|
34
35
|
end
|
35
36
|
|
36
|
-
def encoding
|
37
|
+
def encoding
|
37
38
|
ptr = cstruct[:encoding]
|
38
39
|
ptr.null? ? nil : ptr.read_string
|
39
40
|
end
|
40
41
|
|
41
|
-
def
|
42
|
+
def version
|
43
|
+
cstruct[:version]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.read_io io, url, encoding, options
|
42
47
|
wrap_with_error_handling do
|
43
48
|
LibXML.xmlReadIO(IoCallbacks.reader(io), nil, nil, url, encoding, options)
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
47
|
-
def self.read_memory(string, url, encoding, options)
|
52
|
+
def self.read_memory(string, url, encoding, options)
|
48
53
|
wrap_with_error_handling do
|
49
54
|
LibXML.xmlReadMemory(string, string.length, url, encoding, options)
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
53
|
-
def dup
|
58
|
+
def dup deep = 1
|
54
59
|
dup_ptr = LibXML.xmlCopyDoc(cstruct, deep)
|
55
60
|
return nil if dup_ptr.null?
|
56
61
|
|
@@ -61,15 +66,19 @@ module Nokogiri
|
|
61
66
|
self.class.wrap(dup_ptr)
|
62
67
|
end
|
63
68
|
|
69
|
+
def remove_namespaces!
|
70
|
+
self.class.recursively_remove_namespaces_from_node(root)
|
71
|
+
end
|
72
|
+
|
64
73
|
class << self
|
65
|
-
def new(*args)
|
74
|
+
def new(*args)
|
66
75
|
version = args.first || "1.0"
|
67
76
|
doc = wrap(LibXML.xmlNewDoc(version))
|
68
77
|
doc.send :initialize, *args
|
69
78
|
doc
|
70
79
|
end
|
71
80
|
|
72
|
-
def wrap
|
81
|
+
def wrap doc_struct
|
73
82
|
if doc_struct.is_a?(FFI::Pointer)
|
74
83
|
# cast native pointers up into a doc cstruct
|
75
84
|
return nil if doc_struct.null?
|
@@ -88,7 +97,7 @@ module Nokogiri
|
|
88
97
|
private
|
89
98
|
|
90
99
|
class << self
|
91
|
-
def wrap_with_error_handling(&block)
|
100
|
+
def wrap_with_error_handling(&block)
|
92
101
|
error_list = []
|
93
102
|
LibXML.xmlInitParser()
|
94
103
|
LibXML.xmlResetLastError()
|
@@ -111,8 +120,16 @@ module Nokogiri
|
|
111
120
|
document.errors = error_list
|
112
121
|
return document
|
113
122
|
end
|
123
|
+
|
124
|
+
def recursively_remove_namespaces_from_node(node)
|
125
|
+
node.cstruct[:ns] = nil
|
126
|
+
node.children.each do |child|
|
127
|
+
recursively_remove_namespaces_from_node(child)
|
128
|
+
end
|
129
|
+
end
|
114
130
|
end
|
115
131
|
|
116
132
|
end
|
117
133
|
end
|
118
134
|
end
|
135
|
+
# :startdoc:
|
@@ -9,11 +9,6 @@ module Nokogiri
|
|
9
9
|
|
10
10
|
node = Node.wrap(node_cstruct, self)
|
11
11
|
|
12
|
-
if node.document.child && node.document.child.node_type == ELEMENT_NODE
|
13
|
-
# TODO: node_type check should be ported into master, because of e.g. DTD nodes
|
14
|
-
node.cstruct[:ns] = node.document.children.first.cstruct[:ns]
|
15
|
-
end
|
16
|
-
|
17
12
|
node.send :initialize, document, *rest
|
18
13
|
yield node if block_given?
|
19
14
|
|
data/lib/nokogiri/ffi/xml/dtd.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
# :stopdoc:
|
1
2
|
module Nokogiri
|
2
3
|
module XML
|
3
4
|
class DTD < Node
|
4
|
-
# :stopdoc:
|
5
5
|
def validate document
|
6
6
|
error_list = []
|
7
7
|
ctxt = LibXML.xmlNewValidCtxt
|
@@ -16,6 +16,14 @@ module Nokogiri
|
|
16
16
|
error_list
|
17
17
|
end
|
18
18
|
|
19
|
+
def system_id
|
20
|
+
cstruct[:system_id]
|
21
|
+
end
|
22
|
+
|
23
|
+
def external_id
|
24
|
+
cstruct[:external_id]
|
25
|
+
end
|
26
|
+
|
19
27
|
def elements
|
20
28
|
internal_attributes :elements
|
21
29
|
end
|
@@ -24,6 +32,10 @@ module Nokogiri
|
|
24
32
|
internal_attributes :entities
|
25
33
|
end
|
26
34
|
|
35
|
+
def attributes
|
36
|
+
internal_attributes :attributes
|
37
|
+
end
|
38
|
+
|
27
39
|
def notations
|
28
40
|
attr_ptr = cstruct[:notations]
|
29
41
|
return nil if attr_ptr.null?
|
@@ -51,8 +63,7 @@ module Nokogiri
|
|
51
63
|
LibXML.xmlHashScan(attr_ptr, proc, nil)
|
52
64
|
ahash
|
53
65
|
end
|
54
|
-
|
55
|
-
# :startdoc:
|
56
66
|
end
|
57
67
|
end
|
58
68
|
end
|
69
|
+
# :startdoc:
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
class ElementContent
|
5
|
+
attr_accessor :cstruct
|
6
|
+
|
7
|
+
def self.wrap pointer, document
|
8
|
+
return nil if pointer.null?
|
9
|
+
|
10
|
+
c = ElementContent.allocate
|
11
|
+
c.cstruct = LibXML::XmlElementContent.new pointer
|
12
|
+
c.instance_variable_set :@document, document
|
13
|
+
c
|
14
|
+
end
|
15
|
+
|
16
|
+
def type
|
17
|
+
cstruct[:type]
|
18
|
+
end
|
19
|
+
|
20
|
+
def prefix
|
21
|
+
cstruct[:prefix]
|
22
|
+
end
|
23
|
+
|
24
|
+
def occur
|
25
|
+
cstruct[:ocur]
|
26
|
+
end
|
27
|
+
|
28
|
+
def name
|
29
|
+
cstruct[:name]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def c1
|
34
|
+
self.class.wrap cstruct[:c1], document
|
35
|
+
end
|
36
|
+
|
37
|
+
def c2
|
38
|
+
self.class.wrap cstruct[:c2], document
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# :startdoc:
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
class ElementDecl < Nokogiri::XML::Node
|
5
|
+
def element_type
|
6
|
+
cstruct[:etype]
|
7
|
+
end
|
8
|
+
|
9
|
+
def prefix
|
10
|
+
cstruct[:prefix]
|
11
|
+
end
|
12
|
+
|
13
|
+
def content
|
14
|
+
ElementContent.wrap cstruct[:content], document
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# :startdoc:
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
class EntityDecl < Nokogiri::XML::Node
|
5
|
+
def content
|
6
|
+
cstruct[:content]
|
7
|
+
end
|
8
|
+
|
9
|
+
def entity_type
|
10
|
+
cstruct[:etype]
|
11
|
+
end
|
12
|
+
|
13
|
+
def external_id
|
14
|
+
cstruct[:external_id]
|
15
|
+
end
|
16
|
+
|
17
|
+
def system_id
|
18
|
+
cstruct[:system_id]
|
19
|
+
end
|
20
|
+
|
21
|
+
def original_content
|
22
|
+
cstruct[:orig]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# :startdoc:
|
@@ -18,13 +18,41 @@ module Nokogiri
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def internal_subset
|
21
|
-
return nil if cstruct[:doc].null?
|
22
21
|
doc = cstruct.document
|
23
22
|
dtd = LibXML.xmlGetIntSubset(doc)
|
24
23
|
return nil if dtd.null?
|
25
24
|
Node.wrap(dtd)
|
26
25
|
end
|
27
26
|
|
27
|
+
def external_subset
|
28
|
+
doc = cstruct.document
|
29
|
+
return nil if doc[:extSubset].null?
|
30
|
+
|
31
|
+
Node.wrap(doc[:extSubset])
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_internal_subset name, external_id, system_id
|
35
|
+
raise("Document already has an internal subset") if internal_subset
|
36
|
+
|
37
|
+
doc = cstruct.document
|
38
|
+
dtd_ptr = LibXML.xmlCreateIntSubset doc, name, external_id, system_id
|
39
|
+
|
40
|
+
return nil if dtd_ptr.null?
|
41
|
+
|
42
|
+
Node.wrap dtd_ptr
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_external_subset name, external_id, system_id
|
46
|
+
raise("Document already has an external subset") if external_subset
|
47
|
+
|
48
|
+
doc = cstruct.document
|
49
|
+
dtd_ptr = LibXML.xmlNewDtd doc, name, external_id, system_id
|
50
|
+
|
51
|
+
return nil if dtd_ptr.null?
|
52
|
+
|
53
|
+
Node.wrap dtd_ptr
|
54
|
+
end
|
55
|
+
|
28
56
|
def dup(deep = 1)
|
29
57
|
dup_ptr = LibXML.xmlDocCopyNode(cstruct, cstruct.document, deep)
|
30
58
|
return nil if dup_ptr.null?
|
@@ -61,7 +89,7 @@ module Nokogiri
|
|
61
89
|
|
62
90
|
set = NodeSet.new child.document
|
63
91
|
set_ptr = LibXML.xmlXPathNodeSetCreate(child.cstruct)
|
64
|
-
|
92
|
+
|
65
93
|
set.cstruct = LibXML::XmlNodeSet.new(set_ptr)
|
66
94
|
return set unless child
|
67
95
|
|
@@ -109,7 +137,7 @@ module Nokogiri
|
|
109
137
|
end
|
110
138
|
|
111
139
|
def attribute(name)
|
112
|
-
|
140
|
+
attribute_nodes.find { |x| x.name == name }
|
113
141
|
end
|
114
142
|
|
115
143
|
def attribute_with_ns(name, namespace)
|
@@ -266,11 +294,13 @@ module Nokogiri
|
|
266
294
|
when ELEMENT_NODE then [XML::Element]
|
267
295
|
when TEXT_NODE then [XML::Text]
|
268
296
|
when ENTITY_REF_NODE then [XML::EntityReference]
|
297
|
+
when ATTRIBUTE_DECL then [XML::AttributeDecl, LibXML::XmlAttribute]
|
298
|
+
when ELEMENT_DECL then [XML::ElementDecl, LibXML::XmlElement]
|
269
299
|
when COMMENT_NODE then [XML::Comment]
|
270
300
|
when DOCUMENT_FRAG_NODE then [XML::DocumentFragment]
|
271
301
|
when PI_NODE then [XML::ProcessingInstruction]
|
272
302
|
when ATTRIBUTE_NODE then [XML::Attr]
|
273
|
-
when ENTITY_DECL then [XML::
|
303
|
+
when ENTITY_DECL then [XML::EntityDecl, LibXML::XmlEntity]
|
274
304
|
when CDATA_SECTION_NODE then [XML::CDATA]
|
275
305
|
when DTD_NODE then [XML::DTD, LibXML::XmlDtd]
|
276
306
|
else [XML::Node]
|
@@ -316,6 +346,7 @@ module Nokogiri
|
|
316
346
|
|
317
347
|
def self.reparent_node_with(node, other, &block)
|
318
348
|
raise(ArgumentError, "node must be a Nokogiri::XML::Node") unless node.is_a?(Nokogiri::XML::Node)
|
349
|
+
raise(ArgumentError, "cannot reparent a document node") if node.node_type == DOCUMENT_NODE || node.node_type == HTML_DOCUMENT_NODE
|
319
350
|
|
320
351
|
# If a document fragment is added, we need to reparent all of it's
|
321
352
|
# children
|
@@ -326,6 +357,11 @@ module Nokogiri
|
|
326
357
|
return node
|
327
358
|
end
|
328
359
|
|
360
|
+
if node.type == TEXT_NODE
|
361
|
+
node.cstruct.keep_reference_from_document!
|
362
|
+
node.cstruct = LibXML::XmlNode.new(LibXML.xmlDocCopyNode(node.cstruct, other.cstruct.document, 1))
|
363
|
+
end
|
364
|
+
|
329
365
|
if node.cstruct[:doc] == other.cstruct[:doc]
|
330
366
|
LibXML.xmlUnlinkNode(node.cstruct)
|
331
367
|
if node.type == TEXT_NODE && other.type == TEXT_NODE && Nokogiri.is_2_6_16?
|
@@ -358,8 +394,10 @@ module Nokogiri
|
|
358
394
|
end
|
359
395
|
|
360
396
|
def self.relink_namespace(reparented_struct)
|
397
|
+
return if reparented_struct[:parent].null?
|
398
|
+
|
361
399
|
# Make sure that our reparented node has the correct namespaces
|
362
|
-
if reparented_struct[:doc] != reparented_struct[:parent]
|
400
|
+
if reparented_struct[:ns].null? && reparented_struct[:doc] != reparented_struct[:parent]
|
363
401
|
LibXML.xmlSetNs(reparented_struct, LibXML::XmlNode.new(reparented_struct[:parent])[:ns])
|
364
402
|
end
|
365
403
|
|
@@ -402,3 +440,5 @@ module Nokogiri
|
|
402
440
|
end
|
403
441
|
end
|
404
442
|
end
|
443
|
+
class Nokogiri::XML::Element < Nokogiri::XML::Node; end
|
444
|
+
class Nokogiri::XML::CharacterData < Nokogiri::XML::Node; end
|