nokogiri-maglev- 1.5.0.1
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.
- data/.autotest +26 -0
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +544 -0
- data/CHANGELOG.rdoc +532 -0
- data/Manifest.txt +283 -0
- data/README.ja.rdoc +106 -0
- data/README.rdoc +174 -0
- data/Rakefile +171 -0
- data/bin/nokogiri +53 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +124 -0
- data/ext/nokogiri/html_document.c +154 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +276 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +94 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/nokogiri.c +115 -0
- data/ext/nokogiri/nokogiri.h +160 -0
- data/ext/nokogiri/st.c +576 -0
- data/ext/nokogiri/xml_attr.c +94 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +56 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +54 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +478 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- 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_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +56 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +84 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +1397 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +418 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +684 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +162 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +293 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +199 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +115 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +58 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +50 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +315 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +265 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/css.rb +27 -0
- data/lib/nokogiri/css/node.rb +99 -0
- data/lib/nokogiri/css/parser.rb +677 -0
- data/lib/nokogiri/css/parser.y +237 -0
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +152 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +171 -0
- data/lib/nokogiri/decorators/slop.rb +35 -0
- data/lib/nokogiri/html.rb +36 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +213 -0
- data/lib/nokogiri/html/document_fragment.rb +41 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/entity_lookup.rb +13 -0
- data/lib/nokogiri/html/sax/parser.rb +52 -0
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +88 -0
- data/lib/nokogiri/xml.rb +67 -0
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +426 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +234 -0
- data/lib/nokogiri/xml/document_fragment.rb +98 -0
- data/lib/nokogiri/xml/dtd.rb +22 -0
- 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 +19 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +915 -0
- data/lib/nokogiri/xml/node/save_options.rb +61 -0
- data/lib/nokogiri/xml/node_set.rb +357 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +93 -0
- 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/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +112 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +4 -0
- data/lib/nokogiri/xml/sax/document.rb +164 -0
- data/lib/nokogiri/xml/sax/parser.rb +115 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +63 -0
- data/lib/nokogiri/xml/syntax_error.rb +47 -0
- data/lib/nokogiri/xml/text.rb +9 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +52 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xsd/xmlparser/nokogiri.rb +90 -0
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +152 -0
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +94 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +303 -0
- data/test/css/test_tokenizer.rb +198 -0
- data/test/css/test_xpath_visitor.rb +85 -0
- data/test/decorators/test_slop.rb +16 -0
- data/test/files/2ch.html +108 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/staff.dtd +10 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/helper.rb +173 -0
- data/test/html/sax/test_parser.rb +139 -0
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +165 -0
- data/test/html/test_document.rb +472 -0
- data/test/html/test_document_encoding.rb +138 -0
- data/test/html/test_document_fragment.rb +255 -0
- data/test/html/test_element_description.rb +101 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +193 -0
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +135 -0
- data/test/test_css_cache.rb +45 -0
- data/test/test_encoding_handler.rb +46 -0
- data/test/test_memory_leak.rb +72 -0
- data/test/test_nokogiri.rb +133 -0
- data/test/test_reader.rb +425 -0
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +193 -0
- data/test/xml/node/test_save_options.rb +28 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +338 -0
- data/test/xml/sax/test_parser_context.rb +113 -0
- data/test/xml/sax/test_push_parser.rb +156 -0
- data/test/xml/test_attr.rb +65 -0
- data/test/xml/test_attribute_decl.rb +86 -0
- data/test/xml/test_builder.rb +227 -0
- data/test/xml/test_cdata.rb +50 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +697 -0
- data/test/xml/test_document_encoding.rb +26 -0
- data/test/xml/test_document_fragment.rb +192 -0
- data/test/xml/test_dtd.rb +107 -0
- data/test/xml/test_dtd_encoding.rb +33 -0
- 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 +122 -0
- data/test/xml/test_entity_reference.rb +21 -0
- data/test/xml/test_namespace.rb +70 -0
- data/test/xml/test_node.rb +917 -0
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +107 -0
- data/test/xml/test_node_reparenting.rb +334 -0
- data/test/xml/test_node_set.rb +742 -0
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +126 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +94 -0
- data/test/xml/test_syntax_error.rb +12 -0
- data/test/xml/test_text.rb +47 -0
- data/test/xml/test_unparented_node.rb +381 -0
- data/test/xml/test_xpath.rb +237 -0
- data/test/xslt/test_custom_functions.rb +94 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +548 -0
@@ -0,0 +1,234 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
##
|
4
|
+
# Nokogiri::XML::Document is the main entry point for dealing with
|
5
|
+
# XML documents. The Document is created by parsing an XML document.
|
6
|
+
# See Nokogiri.XML()
|
7
|
+
#
|
8
|
+
# For searching a Document, see Nokogiri::XML::Node#css and
|
9
|
+
# Nokogiri::XML::Node#xpath
|
10
|
+
class Document < Nokogiri::XML::Node
|
11
|
+
##
|
12
|
+
# Parse an XML file. +string_or_io+ may be a String, or any object that
|
13
|
+
# responds to _read_ and _close_ such as an IO, or StringIO.
|
14
|
+
# +url+ is resource where this document is located. +encoding+ is the
|
15
|
+
# encoding that should be used when processing the document. +options+
|
16
|
+
# is a number that sets options in the parser, such as
|
17
|
+
# Nokogiri::XML::ParseOptions::RECOVER. See the constants in
|
18
|
+
# Nokogiri::XML::ParseOptions.
|
19
|
+
def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block
|
20
|
+
|
21
|
+
options = Nokogiri::XML::ParseOptions.new(options) if Fixnum === options
|
22
|
+
# Give the options to the user
|
23
|
+
yield options if block_given?
|
24
|
+
|
25
|
+
if string_or_io.respond_to?(:read)
|
26
|
+
url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
|
27
|
+
return read_io(string_or_io, url, encoding, options.to_i)
|
28
|
+
end
|
29
|
+
|
30
|
+
# read_memory pukes on empty docs
|
31
|
+
return new if string_or_io.nil? or string_or_io.empty?
|
32
|
+
|
33
|
+
read_memory(string_or_io, url, encoding, options.to_i)
|
34
|
+
end
|
35
|
+
|
36
|
+
# A list of Nokogiri::XML::SyntaxError found when parsing a document
|
37
|
+
attr_accessor :errors
|
38
|
+
|
39
|
+
def initialize *args # :nodoc:
|
40
|
+
@errors = []
|
41
|
+
@decorators = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Create an element with +name+, and optionally setting the content and attributes.
|
46
|
+
#
|
47
|
+
# doc.create_element "div" # <div></div>
|
48
|
+
# doc.create_element "div", :class => "container" # <div class='container'></div>
|
49
|
+
# doc.create_element "div", "contents" # <div>contents</div>
|
50
|
+
# doc.create_element "div", "contents", :class => "container" # <div class='container'>contents</div>
|
51
|
+
# doc.create_element "div" { |node| node['class'] = "container" } # <div class='container'></div>
|
52
|
+
#
|
53
|
+
def create_element name, *args, &block
|
54
|
+
elm = Nokogiri::XML::Element.new(name, self, &block)
|
55
|
+
args.each do |arg|
|
56
|
+
case arg
|
57
|
+
when Hash
|
58
|
+
arg.each { |k,v|
|
59
|
+
key = k.to_s
|
60
|
+
if key =~ /^xmlns(:\w+)?$/
|
61
|
+
ns_name = key.split(":", 2)[1]
|
62
|
+
elm.add_namespace_definition ns_name, v
|
63
|
+
next
|
64
|
+
end
|
65
|
+
elm[k.to_s] = v.to_s
|
66
|
+
}
|
67
|
+
else
|
68
|
+
elm.content = arg
|
69
|
+
end
|
70
|
+
end
|
71
|
+
elm
|
72
|
+
end
|
73
|
+
|
74
|
+
# Create a text node with +text+
|
75
|
+
def create_text_node text, &block
|
76
|
+
Nokogiri::XML::Text.new(text.to_s, self, &block)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Create a CDATA element containing +text+
|
80
|
+
def create_cdata text
|
81
|
+
Nokogiri::XML::CDATA.new(self, text.to_s)
|
82
|
+
end
|
83
|
+
|
84
|
+
# The name of this document. Always returns "document"
|
85
|
+
def name
|
86
|
+
'document'
|
87
|
+
end
|
88
|
+
|
89
|
+
# A reference to +self+
|
90
|
+
def document
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Recursively get all namespaces from this node and its subtree and
|
96
|
+
# return them as a hash.
|
97
|
+
#
|
98
|
+
# For example, given this document:
|
99
|
+
#
|
100
|
+
# <root xmlns:foo="bar">
|
101
|
+
# <bar xmlns:hello="world" />
|
102
|
+
# </root>
|
103
|
+
#
|
104
|
+
# This method will return:
|
105
|
+
#
|
106
|
+
# { 'xmlns:foo' => 'bar', 'xmlns:hello' => 'world' }
|
107
|
+
#
|
108
|
+
# WARNING: this method will clobber duplicate names in the keys.
|
109
|
+
# For example, given this document:
|
110
|
+
#
|
111
|
+
# <root xmlns:foo="bar">
|
112
|
+
# <bar xmlns:foo="baz" />
|
113
|
+
# </root>
|
114
|
+
#
|
115
|
+
# The hash returned will look like this: { 'xmlns:foo' => 'bar' }
|
116
|
+
#
|
117
|
+
# Non-prefixed default namespaces (as in "xmlns=") are not included
|
118
|
+
# in the hash.
|
119
|
+
#
|
120
|
+
# Note this is a very expensive operation in current implementation, as it
|
121
|
+
# traverses the entire graph, and also has to bring each node accross the
|
122
|
+
# libxml bridge into a ruby object.
|
123
|
+
def collect_namespaces
|
124
|
+
ns = {}
|
125
|
+
traverse { |j| ns.merge!(j.namespaces) }
|
126
|
+
ns
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get the list of decorators given +key+
|
130
|
+
def decorators key
|
131
|
+
@decorators ||= Hash.new
|
132
|
+
@decorators[key] ||= []
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Validate this Document against it's DTD. Returns a list of errors on
|
137
|
+
# the document or +nil+ when there is no DTD.
|
138
|
+
def validate
|
139
|
+
return nil unless internal_subset
|
140
|
+
internal_subset.validate self
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Explore a document with shortcut methods. See Nokogiri::Slop for details.
|
145
|
+
#
|
146
|
+
# Note that any nodes that have been instantiated before #slop!
|
147
|
+
# is called will not be decorated with sloppy behavior. So, if you're in
|
148
|
+
# irb, the preferred idiom is:
|
149
|
+
#
|
150
|
+
# irb> doc = Nokogiri::Slop my_markup
|
151
|
+
#
|
152
|
+
# and not
|
153
|
+
#
|
154
|
+
# irb> doc = Nokogiri::HTML my_markup
|
155
|
+
# ... followed by irb's implicit inspect (and therefore instantiation of every node) ...
|
156
|
+
# irb> doc.slop!
|
157
|
+
# ... which does absolutely nothing.
|
158
|
+
#
|
159
|
+
def slop!
|
160
|
+
unless decorators(XML::Node).include? Nokogiri::Decorators::Slop
|
161
|
+
decorators(XML::Node) << Nokogiri::Decorators::Slop
|
162
|
+
decorate!
|
163
|
+
end
|
164
|
+
|
165
|
+
self
|
166
|
+
end
|
167
|
+
|
168
|
+
##
|
169
|
+
# Apply any decorators to +node+
|
170
|
+
def decorate node
|
171
|
+
return unless @decorators
|
172
|
+
@decorators.each { |klass,list|
|
173
|
+
next unless node.is_a?(klass)
|
174
|
+
list.each { |moodule| node.extend(moodule) }
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
alias :to_xml :serialize
|
179
|
+
alias :clone :dup
|
180
|
+
|
181
|
+
# Get the hash of namespaces on the root Nokogiri::XML::Node
|
182
|
+
def namespaces
|
183
|
+
root ? root.namespaces : {}
|
184
|
+
end
|
185
|
+
|
186
|
+
##
|
187
|
+
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
188
|
+
# Returns an empty fragment if +tags+ is nil.
|
189
|
+
def fragment tags = nil
|
190
|
+
DocumentFragment.new(self, tags, self.root)
|
191
|
+
end
|
192
|
+
|
193
|
+
undef_method :swap, :parent, :namespace, :default_namespace=
|
194
|
+
undef_method :add_namespace_definition, :attributes
|
195
|
+
undef_method :namespace_definitions, :line, :add_namespace
|
196
|
+
|
197
|
+
def add_child child
|
198
|
+
raise "Document already has a root node" if root
|
199
|
+
if child.type == Node::DOCUMENT_FRAG_NODE
|
200
|
+
raise "Document cannot have multiple root nodes" if child.children.size > 1
|
201
|
+
super(child.children.first)
|
202
|
+
else
|
203
|
+
super
|
204
|
+
end
|
205
|
+
end
|
206
|
+
alias :<< :add_child
|
207
|
+
|
208
|
+
##
|
209
|
+
# +JRuby+
|
210
|
+
# Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
|
211
|
+
def self.wrap document
|
212
|
+
raise "JRuby only method" unless Nokogiri.jruby?
|
213
|
+
return wrapJavaDocument(document)
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# +JRuby+
|
218
|
+
# Returns Java's org.w3c.dom.document of this Document.
|
219
|
+
def to_java
|
220
|
+
raise "JRuby only method" unless Nokogiri.jruby?
|
221
|
+
return toJavaDocument()
|
222
|
+
end
|
223
|
+
|
224
|
+
private
|
225
|
+
def implied_xpath_context
|
226
|
+
"/"
|
227
|
+
end
|
228
|
+
|
229
|
+
def inspect_attributes
|
230
|
+
[:name, :children]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
class DocumentFragment < Nokogiri::XML::Node
|
4
|
+
##
|
5
|
+
# Create a new DocumentFragment from +tags+.
|
6
|
+
#
|
7
|
+
# If +ctx+ is present, it is used as a context node for the
|
8
|
+
# subtree created, e.g., namespaces will be resolved relative
|
9
|
+
# to +ctx+.
|
10
|
+
def initialize document, tags = nil, ctx = nil
|
11
|
+
return self unless tags
|
12
|
+
|
13
|
+
children = if ctx
|
14
|
+
ctx.parse(tags)
|
15
|
+
else
|
16
|
+
XML::Document.parse("<root>#{tags}</root>") \
|
17
|
+
.xpath("/root/node()")
|
18
|
+
end
|
19
|
+
children.each { |child| child.parent = self }
|
20
|
+
end
|
21
|
+
|
22
|
+
###
|
23
|
+
# return the name for DocumentFragment
|
24
|
+
def name
|
25
|
+
'#document-fragment'
|
26
|
+
end
|
27
|
+
|
28
|
+
###
|
29
|
+
# Convert this DocumentFragment to a string
|
30
|
+
def to_s
|
31
|
+
children.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
###
|
35
|
+
# Convert this DocumentFragment to html
|
36
|
+
# See Nokogiri::XML::NodeSet#to_html
|
37
|
+
def to_html *args
|
38
|
+
if Nokogiri.jruby?
|
39
|
+
options = args.first.is_a?(Hash) ? args.shift : {}
|
40
|
+
if !options[:save_with]
|
41
|
+
options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
|
42
|
+
end
|
43
|
+
args.insert(0, options)
|
44
|
+
end
|
45
|
+
children.to_html(*args)
|
46
|
+
end
|
47
|
+
|
48
|
+
###
|
49
|
+
# Convert this DocumentFragment to xhtml
|
50
|
+
# See Nokogiri::XML::NodeSet#to_xhtml
|
51
|
+
def to_xhtml *args
|
52
|
+
if Nokogiri.jruby?
|
53
|
+
options = args.first.is_a?(Hash) ? args.shift : {}
|
54
|
+
if !options[:save_with]
|
55
|
+
options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
|
56
|
+
end
|
57
|
+
args.insert(0, options)
|
58
|
+
end
|
59
|
+
children.to_xhtml(*args)
|
60
|
+
end
|
61
|
+
|
62
|
+
###
|
63
|
+
# Convert this DocumentFragment to xml
|
64
|
+
# See Nokogiri::XML::NodeSet#to_xml
|
65
|
+
def to_xml *args
|
66
|
+
children.to_xml(*args)
|
67
|
+
end
|
68
|
+
|
69
|
+
###
|
70
|
+
# Search this fragment. See Nokogiri::XML::Node#css
|
71
|
+
def css *args
|
72
|
+
if children.any?
|
73
|
+
children.css(*args)
|
74
|
+
else
|
75
|
+
NodeSet.new(document)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
alias :serialize :to_s
|
80
|
+
|
81
|
+
class << self
|
82
|
+
####
|
83
|
+
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
84
|
+
def parse tags
|
85
|
+
self.new(XML::Document.new, tags)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def coerce data
|
92
|
+
return super unless String === data
|
93
|
+
|
94
|
+
document.fragment(data).children
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
class DTD < Nokogiri::XML::Node
|
4
|
+
undef_method :attribute_nodes
|
5
|
+
undef_method :values
|
6
|
+
undef_method :content
|
7
|
+
undef_method :namespace
|
8
|
+
undef_method :namespace_definitions
|
9
|
+
undef_method :line if method_defined?(:line)
|
10
|
+
|
11
|
+
def keys
|
12
|
+
attributes.keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def each &block
|
16
|
+
attributes.each { |key, value|
|
17
|
+
block.call([key, value])
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
###
|
4
|
+
# Represents the allowed content in an Element Declaration inside a DTD:
|
5
|
+
#
|
6
|
+
# <?xml version="1.0"?><?TEST-STYLE PIDATA?>
|
7
|
+
# <!DOCTYPE staff SYSTEM "staff.dtd" [
|
8
|
+
# <!ELEMENT div1 (head, (p | list | note)*, div2*)>
|
9
|
+
# ]>
|
10
|
+
# </root>
|
11
|
+
#
|
12
|
+
# ElementContent represents the tree inside the <!ELEMENT> tag shown above
|
13
|
+
# that lists the possible content for the div1 tag.
|
14
|
+
class ElementContent
|
15
|
+
# Possible definitions of type
|
16
|
+
PCDATA = 1
|
17
|
+
ELEMENT = 2
|
18
|
+
SEQ = 3
|
19
|
+
OR = 4
|
20
|
+
|
21
|
+
# Possible content occurrences
|
22
|
+
ONCE = 1
|
23
|
+
OPT = 2
|
24
|
+
MULT = 3
|
25
|
+
PLUS = 4
|
26
|
+
|
27
|
+
attr_reader :document
|
28
|
+
|
29
|
+
###
|
30
|
+
# Get the children of this ElementContent node
|
31
|
+
def children
|
32
|
+
[c1, c2].compact
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
class ElementDecl < Nokogiri::XML::Node
|
4
|
+
undef_method :namespace
|
5
|
+
undef_method :namespace_definitions
|
6
|
+
undef_method :line if method_defined?(:line)
|
7
|
+
|
8
|
+
def inspect
|
9
|
+
"#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
class EntityDecl < Nokogiri::XML::Node
|
4
|
+
undef_method :attribute_nodes
|
5
|
+
undef_method :attributes
|
6
|
+
undef_method :namespace
|
7
|
+
undef_method :namespace_definitions
|
8
|
+
undef_method :line if method_defined?(:line)
|
9
|
+
|
10
|
+
def self.new name, doc, *args
|
11
|
+
doc.create_entity(name, *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
"#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{to_s.inspect}>"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|