nokogiri-backport 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1682 -0
- data/LICENSE.md +9 -0
- data/README.md +272 -0
- data/bin/nokogiri +118 -0
- data/dependencies.yml +74 -0
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +178 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +148 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +282 -0
- data/ext/java/nokogiri/HtmlSaxPushParser.java +222 -0
- data/ext/java/nokogiri/NokogiriService.java +597 -0
- data/ext/java/nokogiri/XmlAttr.java +162 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +129 -0
- data/ext/java/nokogiri/XmlCdata.java +82 -0
- data/ext/java/nokogiri/XmlComment.java +97 -0
- data/ext/java/nokogiri/XmlDocument.java +633 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +185 -0
- data/ext/java/nokogiri/XmlDtd.java +481 -0
- data/ext/java/nokogiri/XmlElement.java +68 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +147 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +157 -0
- data/ext/java/nokogiri/XmlEntityReference.java +101 -0
- data/ext/java/nokogiri/XmlNamespace.java +199 -0
- data/ext/java/nokogiri/XmlNode.java +1684 -0
- data/ext/java/nokogiri/XmlNodeSet.java +434 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +100 -0
- data/ext/java/nokogiri/XmlReader.java +531 -0
- data/ext/java/nokogiri/XmlRelaxng.java +151 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +374 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +286 -0
- data/ext/java/nokogiri/XmlSchema.java +388 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +138 -0
- data/ext/java/nokogiri/XmlText.java +110 -0
- data/ext/java/nokogiri/XmlXpathContext.java +301 -0
- data/ext/java/nokogiri/XsltStylesheet.java +347 -0
- data/ext/java/nokogiri/internals/ClosedStreamException.java +10 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +151 -0
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +116 -0
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +69 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +734 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +217 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +127 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +100 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +78 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +180 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +72 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +60 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +87 -0
- data/ext/java/nokogiri/internals/ParserContext.java +259 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +488 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +778 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +73 -0
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +168 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +274 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +367 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
- data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +166 -0
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1745 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +685 -0
- data/ext/nokogiri/depend +477 -0
- data/ext/nokogiri/extconf.rb +836 -0
- data/ext/nokogiri/html_document.c +171 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -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 +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +135 -0
- data/ext/nokogiri/nokogiri.h +130 -0
- data/ext/nokogiri/xml_attr.c +103 -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 +62 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +622 -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 +63 -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 +111 -0
- data/ext/nokogiri/xml_namespace.h +14 -0
- data/ext/nokogiri/xml_node.c +1773 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +486 -0
- data/ext/nokogiri/xml_node_set.h +12 -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 +657 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +179 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +305 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +159 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +276 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +64 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +374 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +263 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri/css/node.rb +53 -0
- data/lib/nokogiri/css/parser.rb +751 -0
- data/lib/nokogiri/css/parser.y +272 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +8 -0
- data/lib/nokogiri/css/tokenizer.rb +154 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +260 -0
- data/lib/nokogiri/css.rb +28 -0
- data/lib/nokogiri/decorators/slop.rb +43 -0
- data/lib/nokogiri/html/builder.rb +36 -0
- data/lib/nokogiri/html/document.rb +322 -0
- data/lib/nokogiri/html/document_fragment.rb +50 -0
- data/lib/nokogiri/html/element_description.rb +24 -0
- data/lib/nokogiri/html/element_description_defaults.rb +672 -0
- data/lib/nokogiri/html/entity_lookup.rb +14 -0
- data/lib/nokogiri/html/sax/parser.rb +63 -0
- data/lib/nokogiri/html/sax/parser_context.rb +17 -0
- data/lib/nokogiri/html/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html.rb +38 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +5 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml/attr.rb +15 -0
- data/lib/nokogiri/xml/attribute_decl.rb +19 -0
- data/lib/nokogiri/xml/builder.rb +447 -0
- data/lib/nokogiri/xml/cdata.rb +12 -0
- data/lib/nokogiri/xml/character_data.rb +8 -0
- data/lib/nokogiri/xml/document.rb +290 -0
- data/lib/nokogiri/xml/document_fragment.rb +159 -0
- data/lib/nokogiri/xml/dtd.rb +33 -0
- data/lib/nokogiri/xml/element_content.rb +37 -0
- data/lib/nokogiri/xml/element_decl.rb +14 -0
- data/lib/nokogiri/xml/entity_decl.rb +20 -0
- data/lib/nokogiri/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +14 -0
- data/lib/nokogiri/xml/node/save_options.rb +62 -0
- data/lib/nokogiri/xml/node.rb +1240 -0
- data/lib/nokogiri/xml/node_set.rb +372 -0
- data/lib/nokogiri/xml/notation.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +127 -0
- data/lib/nokogiri/xml/pp/character_data.rb +19 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/pp.rb +3 -0
- data/lib/nokogiri/xml/processing_instruction.rb +9 -0
- data/lib/nokogiri/xml/reader.rb +116 -0
- data/lib/nokogiri/xml/relax_ng.rb +37 -0
- data/lib/nokogiri/xml/sax/document.rb +172 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +5 -0
- data/lib/nokogiri/xml/schema.rb +72 -0
- data/lib/nokogiri/xml/searchable.rb +239 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
- data/lib/nokogiri/xml/xpath.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +17 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xslt/stylesheet.rb +26 -0
- data/lib/nokogiri/xslt.rb +57 -0
- data/lib/nokogiri.rb +144 -0
- data/lib/serializer.jar +0 -0
- data/lib/xalan.jar +0 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xml-apis.jar +0 -0
- data/lib/xsd/xmlparser/nokogiri.rb +103 -0
- metadata +531 -0
@@ -0,0 +1,239 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
#
|
5
|
+
# The Searchable module declares the interface used for searching your DOM.
|
6
|
+
#
|
7
|
+
# It implements the public methods `search`, `css`, and `xpath`,
|
8
|
+
# as well as allowing specific implementations to specialize some
|
9
|
+
# of the important behaviors.
|
10
|
+
#
|
11
|
+
module Searchable
|
12
|
+
# Regular expression used by Searchable#search to determine if a query
|
13
|
+
# string is CSS or XPath
|
14
|
+
LOOKS_LIKE_XPATH = /^(\.\/|\/|\.\.|\.$)/
|
15
|
+
|
16
|
+
# @!group Searching via XPath or CSS Queries
|
17
|
+
|
18
|
+
###
|
19
|
+
# call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
|
20
|
+
#
|
21
|
+
# Search this object for +paths+. +paths+ must be one or more XPath or CSS queries:
|
22
|
+
#
|
23
|
+
# node.search("div.employee", ".//title")
|
24
|
+
#
|
25
|
+
# A hash of namespace bindings may be appended:
|
26
|
+
#
|
27
|
+
# node.search('.//bike:tire', {'bike' => 'http://schwinn.com/'})
|
28
|
+
# node.search('bike|tire', {'bike' => 'http://schwinn.com/'})
|
29
|
+
#
|
30
|
+
# For XPath queries, a hash of variable bindings may also be
|
31
|
+
# appended to the namespace bindings. For example:
|
32
|
+
#
|
33
|
+
# node.search('.//address[@domestic=$value]', nil, {:value => 'Yes'})
|
34
|
+
#
|
35
|
+
# Custom XPath functions and CSS pseudo-selectors may also be
|
36
|
+
# defined. To define custom functions create a class and
|
37
|
+
# implement the function you want to define. The first argument
|
38
|
+
# to the method will be the current matching NodeSet. Any other
|
39
|
+
# arguments are ones that you pass in. Note that this class may
|
40
|
+
# appear anywhere in the argument list. For example:
|
41
|
+
#
|
42
|
+
# node.search('.//title[regex(., "\w+")]', 'div.employee:regex("[0-9]+")'
|
43
|
+
# Class.new {
|
44
|
+
# def regex node_set, regex
|
45
|
+
# node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
|
46
|
+
# end
|
47
|
+
# }.new
|
48
|
+
# )
|
49
|
+
#
|
50
|
+
# See Searchable#xpath and Searchable#css for further usage help.
|
51
|
+
def search(*args)
|
52
|
+
paths, handler, ns, binds = extract_params(args)
|
53
|
+
|
54
|
+
xpaths = paths.map(&:to_s).map do |path|
|
55
|
+
(path =~ LOOKS_LIKE_XPATH) ? path : xpath_query_from_css_rule(path, ns)
|
56
|
+
end.flatten.uniq
|
57
|
+
|
58
|
+
xpath(*(xpaths + [ns, handler, binds].compact))
|
59
|
+
end
|
60
|
+
|
61
|
+
alias :/ :search
|
62
|
+
|
63
|
+
###
|
64
|
+
# call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
|
65
|
+
#
|
66
|
+
# Search this object for +paths+, and return only the first
|
67
|
+
# result. +paths+ must be one or more XPath or CSS queries.
|
68
|
+
#
|
69
|
+
# See Searchable#search for more information.
|
70
|
+
def at(*args)
|
71
|
+
search(*args).first
|
72
|
+
end
|
73
|
+
|
74
|
+
alias :% :at
|
75
|
+
|
76
|
+
###
|
77
|
+
# call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
|
78
|
+
#
|
79
|
+
# Search this object for CSS +rules+. +rules+ must be one or more CSS
|
80
|
+
# selectors. For example:
|
81
|
+
#
|
82
|
+
# node.css('title')
|
83
|
+
# node.css('body h1.bold')
|
84
|
+
# node.css('div + p.green', 'div#one')
|
85
|
+
#
|
86
|
+
# A hash of namespace bindings may be appended. For example:
|
87
|
+
#
|
88
|
+
# node.css('bike|tire', {'bike' => 'http://schwinn.com/'})
|
89
|
+
#
|
90
|
+
# Custom CSS pseudo classes may also be defined. To define
|
91
|
+
# custom pseudo classes, create a class and implement the custom
|
92
|
+
# pseudo class you want defined. The first argument to the
|
93
|
+
# method will be the current matching NodeSet. Any other
|
94
|
+
# arguments are ones that you pass in. For example:
|
95
|
+
#
|
96
|
+
# node.css('title:regex("\w+")', Class.new {
|
97
|
+
# def regex node_set, regex
|
98
|
+
# node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
|
99
|
+
# end
|
100
|
+
# }.new)
|
101
|
+
#
|
102
|
+
# Note that the CSS query string is case-sensitive with regards
|
103
|
+
# to your document type. That is, if you're looking for "H1" in
|
104
|
+
# an HTML document, you'll never find anything, since HTML tags
|
105
|
+
# will match only lowercase CSS queries. However, "H1" might be
|
106
|
+
# found in an XML document, where tags names are case-sensitive
|
107
|
+
# (e.g., "H1" is distinct from "h1").
|
108
|
+
#
|
109
|
+
def css(*args)
|
110
|
+
rules, handler, ns, _ = extract_params(args)
|
111
|
+
|
112
|
+
css_internal self, rules, handler, ns
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
|
117
|
+
#
|
118
|
+
# Search this object for CSS +rules+, and return only the first
|
119
|
+
# match. +rules+ must be one or more CSS selectors.
|
120
|
+
#
|
121
|
+
# See Searchable#css for more information.
|
122
|
+
def at_css(*args)
|
123
|
+
css(*args).first
|
124
|
+
end
|
125
|
+
|
126
|
+
###
|
127
|
+
# call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
|
128
|
+
#
|
129
|
+
# Search this node for XPath +paths+. +paths+ must be one or more XPath
|
130
|
+
# queries.
|
131
|
+
#
|
132
|
+
# node.xpath('.//title')
|
133
|
+
#
|
134
|
+
# A hash of namespace bindings may be appended. For example:
|
135
|
+
#
|
136
|
+
# node.xpath('.//foo:name', {'foo' => 'http://example.org/'})
|
137
|
+
# node.xpath('.//xmlns:name', node.root.namespaces)
|
138
|
+
#
|
139
|
+
# A hash of variable bindings may also be appended to the namespace bindings. For example:
|
140
|
+
#
|
141
|
+
# node.xpath('.//address[@domestic=$value]', nil, {:value => 'Yes'})
|
142
|
+
#
|
143
|
+
# Custom XPath functions may also be defined. To define custom
|
144
|
+
# functions create a class and implement the function you want
|
145
|
+
# to define. The first argument to the method will be the
|
146
|
+
# current matching NodeSet. Any other arguments are ones that
|
147
|
+
# you pass in. Note that this class may appear anywhere in the
|
148
|
+
# argument list. For example:
|
149
|
+
#
|
150
|
+
# node.xpath('.//title[regex(., "\w+")]', Class.new {
|
151
|
+
# def regex node_set, regex
|
152
|
+
# node_set.find_all { |node| node['some_attribute'] =~ /#{regex}/ }
|
153
|
+
# end
|
154
|
+
# }.new)
|
155
|
+
#
|
156
|
+
def xpath(*args)
|
157
|
+
paths, handler, ns, binds = extract_params(args)
|
158
|
+
|
159
|
+
xpath_internal self, paths, handler, ns, binds
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
|
164
|
+
#
|
165
|
+
# Search this node for XPath +paths+, and return only the first
|
166
|
+
# match. +paths+ must be one or more XPath queries.
|
167
|
+
#
|
168
|
+
# See Searchable#xpath for more information.
|
169
|
+
def at_xpath(*args)
|
170
|
+
xpath(*args).first
|
171
|
+
end
|
172
|
+
|
173
|
+
# @!endgroup
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def css_internal(node, rules, handler, ns)
|
178
|
+
xpath_internal node, css_rules_to_xpath(rules, ns), handler, ns, nil
|
179
|
+
end
|
180
|
+
|
181
|
+
def xpath_internal(node, paths, handler, ns, binds)
|
182
|
+
document = node.document
|
183
|
+
return NodeSet.new(document) unless document
|
184
|
+
|
185
|
+
if paths.length == 1
|
186
|
+
return xpath_impl(node, paths.first, handler, ns, binds)
|
187
|
+
end
|
188
|
+
|
189
|
+
NodeSet.new(document) do |combined|
|
190
|
+
paths.each do |path|
|
191
|
+
xpath_impl(node, path, handler, ns, binds).each { |set| combined << set }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def xpath_impl(node, path, handler, ns, binds)
|
197
|
+
ctx = XPathContext.new(node)
|
198
|
+
ctx.register_namespaces(ns)
|
199
|
+
path = path.gsub(/xmlns:/, " :") unless Nokogiri.uses_libxml?
|
200
|
+
|
201
|
+
binds.each do |key, value|
|
202
|
+
ctx.register_variable key.to_s, value
|
203
|
+
end if binds
|
204
|
+
|
205
|
+
ctx.evaluate(path, handler)
|
206
|
+
end
|
207
|
+
|
208
|
+
def css_rules_to_xpath(rules, ns)
|
209
|
+
rules.map { |rule| xpath_query_from_css_rule(rule, ns) }
|
210
|
+
end
|
211
|
+
|
212
|
+
def xpath_query_from_css_rule(rule, ns)
|
213
|
+
visitor = Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins.new
|
214
|
+
self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
|
215
|
+
CSS.xpath_for(rule.to_s, {:prefix => implied_xpath_context, :ns => ns,
|
216
|
+
:visitor => visitor})
|
217
|
+
end.join(" | ")
|
218
|
+
end
|
219
|
+
|
220
|
+
def extract_params(params) # :nodoc:
|
221
|
+
handler = params.find do |param|
|
222
|
+
![Hash, String, Symbol].include?(param.class)
|
223
|
+
end
|
224
|
+
params -= [handler] if handler
|
225
|
+
|
226
|
+
hashes = []
|
227
|
+
while Hash === params.last || params.last.nil?
|
228
|
+
hashes << params.pop
|
229
|
+
break if params.empty?
|
230
|
+
end
|
231
|
+
ns, binds = hashes.reverse
|
232
|
+
|
233
|
+
ns ||= document.root ? document.root.namespaces : {}
|
234
|
+
|
235
|
+
[params, handler, ns, binds]
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
###
|
5
|
+
# This class provides information about XML SyntaxErrors. These
|
6
|
+
# exceptions are typically stored on Nokogiri::XML::Document#errors.
|
7
|
+
class SyntaxError < ::Nokogiri::SyntaxError
|
8
|
+
attr_reader :domain
|
9
|
+
attr_reader :code
|
10
|
+
attr_reader :level
|
11
|
+
attr_reader :file
|
12
|
+
attr_reader :line
|
13
|
+
attr_reader :str1
|
14
|
+
attr_reader :str2
|
15
|
+
attr_reader :str3
|
16
|
+
attr_reader :int1
|
17
|
+
attr_reader :column
|
18
|
+
|
19
|
+
###
|
20
|
+
# return true if this is a non error
|
21
|
+
def none?
|
22
|
+
level == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
###
|
26
|
+
# return true if this is a warning
|
27
|
+
def warning?
|
28
|
+
level == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
###
|
32
|
+
# return true if this is an error
|
33
|
+
def error?
|
34
|
+
level == 2
|
35
|
+
end
|
36
|
+
|
37
|
+
###
|
38
|
+
# return true if this error is fatal
|
39
|
+
def fatal?
|
40
|
+
level == 3
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
message = super.chomp
|
45
|
+
[location_to_s, level_to_s, message].
|
46
|
+
compact.join(": ").
|
47
|
+
force_encoding(message.encoding)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def level_to_s
|
53
|
+
case level
|
54
|
+
when 3 then "FATAL"
|
55
|
+
when 2 then "ERROR"
|
56
|
+
when 1 then "WARNING"
|
57
|
+
else nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def nil_or_zero?(attribute)
|
62
|
+
attribute.nil? || attribute.zero?
|
63
|
+
end
|
64
|
+
|
65
|
+
def location_to_s
|
66
|
+
return nil if nil_or_zero?(line) && nil_or_zero?(column)
|
67
|
+
"#{line}:#{column}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Nokogiri
|
3
|
+
module XML
|
4
|
+
class XPathContext
|
5
|
+
|
6
|
+
###
|
7
|
+
# Register namespaces in +namespaces+
|
8
|
+
def register_namespaces(namespaces)
|
9
|
+
namespaces.each do |k, v|
|
10
|
+
k = k.to_s.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
|
11
|
+
register_ns(k, v)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/nokogiri/xml.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'nokogiri/xml/pp'
|
3
|
+
require 'nokogiri/xml/parse_options'
|
4
|
+
require 'nokogiri/xml/sax'
|
5
|
+
require 'nokogiri/xml/searchable'
|
6
|
+
require 'nokogiri/xml/node'
|
7
|
+
require 'nokogiri/xml/attribute_decl'
|
8
|
+
require 'nokogiri/xml/element_decl'
|
9
|
+
require 'nokogiri/xml/element_content'
|
10
|
+
require 'nokogiri/xml/character_data'
|
11
|
+
require 'nokogiri/xml/namespace'
|
12
|
+
require 'nokogiri/xml/attr'
|
13
|
+
require 'nokogiri/xml/dtd'
|
14
|
+
require 'nokogiri/xml/cdata'
|
15
|
+
require 'nokogiri/xml/text'
|
16
|
+
require 'nokogiri/xml/document'
|
17
|
+
require 'nokogiri/xml/document_fragment'
|
18
|
+
require 'nokogiri/xml/processing_instruction'
|
19
|
+
require 'nokogiri/xml/node_set'
|
20
|
+
require 'nokogiri/xml/syntax_error'
|
21
|
+
require 'nokogiri/xml/xpath'
|
22
|
+
require 'nokogiri/xml/xpath_context'
|
23
|
+
require 'nokogiri/xml/builder'
|
24
|
+
require 'nokogiri/xml/reader'
|
25
|
+
require 'nokogiri/xml/notation'
|
26
|
+
require 'nokogiri/xml/entity_decl'
|
27
|
+
require 'nokogiri/xml/entity_reference'
|
28
|
+
require 'nokogiri/xml/schema'
|
29
|
+
require 'nokogiri/xml/relax_ng'
|
30
|
+
|
31
|
+
module Nokogiri
|
32
|
+
class << self
|
33
|
+
###
|
34
|
+
# Parse XML. Convenience method for Nokogiri::XML::Document.parse
|
35
|
+
def XML thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_XML, &block
|
36
|
+
Nokogiri::XML::Document.parse(thing, url, encoding, options, &block)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module XML
|
41
|
+
# Original C14N 1.0 spec canonicalization
|
42
|
+
XML_C14N_1_0 = 0
|
43
|
+
# Exclusive C14N 1.0 spec canonicalization
|
44
|
+
XML_C14N_EXCLUSIVE_1_0 = 1
|
45
|
+
# C14N 1.1 spec canonicalization
|
46
|
+
XML_C14N_1_1 = 2
|
47
|
+
class << self
|
48
|
+
###
|
49
|
+
# Parse an XML document using the Nokogiri::XML::Reader API. See
|
50
|
+
# Nokogiri::XML::Reader for mor information
|
51
|
+
def Reader string_or_io, url = nil, encoding = nil, options = ParseOptions::STRICT
|
52
|
+
|
53
|
+
options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
|
54
|
+
# Give the options to the user
|
55
|
+
yield options if block_given?
|
56
|
+
|
57
|
+
if string_or_io.respond_to? :read
|
58
|
+
return Reader.from_io(string_or_io, url, encoding, options.to_i)
|
59
|
+
end
|
60
|
+
Reader.from_memory(string_or_io, url, encoding, options.to_i)
|
61
|
+
end
|
62
|
+
|
63
|
+
###
|
64
|
+
# Parse XML. Convenience method for Nokogiri::XML::Document.parse
|
65
|
+
def parse thing, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block
|
66
|
+
Document.parse(thing, url, encoding, options, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
####
|
70
|
+
# Parse a fragment from +string+ in to a NodeSet.
|
71
|
+
def fragment string
|
72
|
+
XML::DocumentFragment.parse(string)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Nokogiri
|
3
|
+
module XSLT
|
4
|
+
###
|
5
|
+
# A Stylesheet represents an XSLT Stylesheet object. Stylesheet creation
|
6
|
+
# is done through Nokogiri.XSLT. Here is an example of transforming
|
7
|
+
# an XML::Document with a Stylesheet:
|
8
|
+
#
|
9
|
+
# doc = Nokogiri::XML(File.read('some_file.xml'))
|
10
|
+
# xslt = Nokogiri::XSLT(File.read('some_transformer.xslt'))
|
11
|
+
#
|
12
|
+
# puts xslt.transform(doc)
|
13
|
+
#
|
14
|
+
# See Nokogiri::XSLT::Stylesheet#transform for more transformation
|
15
|
+
# information.
|
16
|
+
class Stylesheet
|
17
|
+
###
|
18
|
+
# Apply an XSLT stylesheet to an XML::Document.
|
19
|
+
# +params+ is an array of strings used as XSLT parameters.
|
20
|
+
# returns serialized document
|
21
|
+
def apply_to document, params = []
|
22
|
+
serialize(transform(document, params))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'nokogiri/xslt/stylesheet'
|
3
|
+
|
4
|
+
module Nokogiri
|
5
|
+
class << self
|
6
|
+
###
|
7
|
+
# Create a Nokogiri::XSLT::Stylesheet with +stylesheet+.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# xslt = Nokogiri::XSLT(File.read(ARGV[0]))
|
12
|
+
#
|
13
|
+
def XSLT stylesheet, modules = {}
|
14
|
+
XSLT.parse(stylesheet, modules)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
###
|
19
|
+
# See Nokogiri::XSLT::Stylesheet for creating and manipulating
|
20
|
+
# Stylesheet object.
|
21
|
+
module XSLT
|
22
|
+
class << self
|
23
|
+
###
|
24
|
+
# Parse the stylesheet in +string+, register any +modules+
|
25
|
+
def parse string, modules = {}
|
26
|
+
modules.each do |url, klass|
|
27
|
+
XSLT.register url, klass
|
28
|
+
end
|
29
|
+
|
30
|
+
if Nokogiri.jruby?
|
31
|
+
Stylesheet.parse_stylesheet_doc(XML.parse(string), string)
|
32
|
+
else
|
33
|
+
Stylesheet.parse_stylesheet_doc(XML.parse(string))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
###
|
38
|
+
# Quote parameters in +params+ for stylesheet safety
|
39
|
+
def quote_params params
|
40
|
+
parray = (params.instance_of?(Hash) ? params.to_a.flatten : params).dup
|
41
|
+
parray.each_with_index do |v,i|
|
42
|
+
if i % 2 > 0
|
43
|
+
parray[i]=
|
44
|
+
if v =~ /'/
|
45
|
+
"concat('#{ v.gsub(/'/, %q{', "'", '}) }')"
|
46
|
+
else
|
47
|
+
"'#{v}'";
|
48
|
+
end
|
49
|
+
else
|
50
|
+
parray[i] = v.to_s
|
51
|
+
end
|
52
|
+
end
|
53
|
+
parray.flatten
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/nokogiri.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# Modify the PATH on windows so that the external DLLs will get loaded.
|
4
|
+
|
5
|
+
require 'rbconfig'
|
6
|
+
|
7
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
8
|
+
require 'nokogiri/jruby/dependencies'
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
13
|
+
require "nokogiri/#{$1}/nokogiri"
|
14
|
+
rescue LoadError => e
|
15
|
+
if e.message =~ /GLIBC/
|
16
|
+
warn <<~EOM
|
17
|
+
|
18
|
+
ERROR: It looks like you're trying to use Nokogiri as a precompiled native gem on a system with glibc < 2.17:
|
19
|
+
|
20
|
+
#{e.message}
|
21
|
+
|
22
|
+
If that's the case, then please install Nokogiri via the `ruby` platform gem:
|
23
|
+
gem install nokogiri --platform=ruby
|
24
|
+
or:
|
25
|
+
bundle config set force_ruby_platform true
|
26
|
+
|
27
|
+
Please visit https://nokogiri.org/tutorials/installing_nokogiri.html for more help.
|
28
|
+
|
29
|
+
EOM
|
30
|
+
raise e
|
31
|
+
end
|
32
|
+
require 'nokogiri/nokogiri'
|
33
|
+
end
|
34
|
+
require 'nokogiri/version'
|
35
|
+
require 'nokogiri/syntax_error'
|
36
|
+
require 'nokogiri/xml'
|
37
|
+
require 'nokogiri/xslt'
|
38
|
+
require 'nokogiri/html'
|
39
|
+
require 'nokogiri/decorators/slop'
|
40
|
+
require 'nokogiri/css'
|
41
|
+
require 'nokogiri/html/builder'
|
42
|
+
|
43
|
+
# Nokogiri parses and searches XML/HTML very quickly, and also has
|
44
|
+
# correctly implemented CSS3 selector support as well as XPath 1.0
|
45
|
+
# support.
|
46
|
+
#
|
47
|
+
# Parsing a document returns either a Nokogiri::XML::Document, or a
|
48
|
+
# Nokogiri::HTML::Document depending on the kind of document you parse.
|
49
|
+
#
|
50
|
+
# Here is an example:
|
51
|
+
#
|
52
|
+
# require 'nokogiri'
|
53
|
+
# require 'open-uri'
|
54
|
+
#
|
55
|
+
# # Get a Nokogiri::HTML:Document for the page we’re interested in...
|
56
|
+
#
|
57
|
+
# doc = Nokogiri::HTML(URI.open('http://www.google.com/search?q=tenderlove'))
|
58
|
+
#
|
59
|
+
# # Do funky things with it using Nokogiri::XML::Node methods...
|
60
|
+
#
|
61
|
+
# ####
|
62
|
+
# # Search for nodes by css
|
63
|
+
# doc.css('h3.r a.l').each do |link|
|
64
|
+
# puts link.content
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# See Nokogiri::XML::Searchable#css for more information about CSS searching.
|
68
|
+
# See Nokogiri::XML::Searchable#xpath for more information about XPath searching.
|
69
|
+
module Nokogiri
|
70
|
+
class << self
|
71
|
+
###
|
72
|
+
# Parse an HTML or XML document. +string+ contains the document.
|
73
|
+
def parse string, url = nil, encoding = nil, options = nil
|
74
|
+
if string.respond_to?(:read) ||
|
75
|
+
/^\s*<(?:!DOCTYPE\s+)?html[\s>]/i === string[0, 512]
|
76
|
+
# Expect an HTML indicator to appear within the first 512
|
77
|
+
# characters of a document. (<?xml ?> + <?xml-stylesheet ?>
|
78
|
+
# shouldn't be that long)
|
79
|
+
Nokogiri.HTML(string, url, encoding,
|
80
|
+
options || XML::ParseOptions::DEFAULT_HTML)
|
81
|
+
else
|
82
|
+
Nokogiri.XML(string, url, encoding,
|
83
|
+
options || XML::ParseOptions::DEFAULT_XML)
|
84
|
+
end.tap { |doc|
|
85
|
+
yield doc if block_given?
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
###
|
90
|
+
# Create a new Nokogiri::XML::DocumentFragment
|
91
|
+
def make input = nil, opts = {}, &blk
|
92
|
+
if input
|
93
|
+
Nokogiri::HTML.fragment(input).children.first
|
94
|
+
else
|
95
|
+
Nokogiri(&blk)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
###
|
100
|
+
# Parse a document and add the Slop decorator. The Slop decorator
|
101
|
+
# implements method_missing such that methods may be used instead of CSS
|
102
|
+
# or XPath. For example:
|
103
|
+
#
|
104
|
+
# doc = Nokogiri::Slop(<<-eohtml)
|
105
|
+
# <html>
|
106
|
+
# <body>
|
107
|
+
# <p>first</p>
|
108
|
+
# <p>second</p>
|
109
|
+
# </body>
|
110
|
+
# </html>
|
111
|
+
# eohtml
|
112
|
+
# assert_equal('second', doc.html.body.p[1].text)
|
113
|
+
#
|
114
|
+
def Slop(*args, &block)
|
115
|
+
Nokogiri(*args, &block).slop!
|
116
|
+
end
|
117
|
+
|
118
|
+
def install_default_aliases
|
119
|
+
# Make sure to support some popular encoding aliases not known by
|
120
|
+
# all iconv implementations.
|
121
|
+
{
|
122
|
+
'Windows-31J' => 'CP932', # Windows-31J is the IANA registered name of CP932.
|
123
|
+
}.each { |alias_name, name|
|
124
|
+
EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
Nokogiri.install_default_aliases
|
130
|
+
end
|
131
|
+
|
132
|
+
###
|
133
|
+
# Parse a document contained in +args+. Nokogiri will try to guess what
|
134
|
+
# type of document you are attempting to parse. For more information, see
|
135
|
+
# Nokogiri.parse
|
136
|
+
#
|
137
|
+
# To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
|
138
|
+
def Nokogiri(*args, &block)
|
139
|
+
if block_given?
|
140
|
+
Nokogiri::HTML::Builder.new(&block).doc.root
|
141
|
+
else
|
142
|
+
Nokogiri.parse(*args)
|
143
|
+
end
|
144
|
+
end
|
data/lib/serializer.jar
ADDED
Binary file
|
data/lib/xalan.jar
ADDED
Binary file
|
data/lib/xercesImpl.jar
ADDED
Binary file
|
data/lib/xml-apis.jar
ADDED
Binary file
|