rubysl-rexml 1.0.0 → 2.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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/lib/rexml/attlistdecl.rb +56 -56
- data/lib/rexml/attribute.rb +155 -149
- data/lib/rexml/cdata.rb +48 -48
- data/lib/rexml/child.rb +82 -82
- data/lib/rexml/comment.rb +59 -59
- data/lib/rexml/doctype.rb +22 -24
- data/lib/rexml/document.rb +185 -129
- data/lib/rexml/dtd/attlistdecl.rb +7 -7
- data/lib/rexml/dtd/dtd.rb +41 -41
- data/lib/rexml/dtd/elementdecl.rb +13 -13
- data/lib/rexml/dtd/entitydecl.rb +49 -49
- data/lib/rexml/dtd/notationdecl.rb +32 -32
- data/lib/rexml/element.rb +122 -107
- data/lib/rexml/encoding.rb +37 -58
- data/lib/rexml/entity.rb +144 -144
- data/lib/rexml/formatters/default.rb +6 -4
- data/lib/rexml/formatters/pretty.rb +11 -8
- data/lib/rexml/formatters/transitive.rb +4 -3
- data/lib/rexml/functions.rb +33 -21
- data/lib/rexml/instruction.rb +49 -49
- data/lib/rexml/light/node.rb +190 -191
- data/lib/rexml/namespace.rb +39 -39
- data/lib/rexml/node.rb +38 -38
- data/lib/rexml/output.rb +17 -12
- data/lib/rexml/parent.rb +26 -25
- data/lib/rexml/parseexception.rb +4 -4
- data/lib/rexml/parsers/baseparser.rb +90 -61
- data/lib/rexml/parsers/lightparser.rb +41 -43
- data/lib/rexml/parsers/pullparser.rb +1 -1
- data/lib/rexml/parsers/sax2parser.rb +233 -198
- data/lib/rexml/parsers/streamparser.rb +6 -2
- data/lib/rexml/parsers/treeparser.rb +9 -6
- data/lib/rexml/parsers/ultralightparser.rb +40 -40
- data/lib/rexml/parsers/xpathparser.rb +51 -52
- data/lib/rexml/quickpath.rb +247 -248
- data/lib/rexml/rexml.rb +9 -10
- data/lib/rexml/sax2listener.rb +92 -92
- data/lib/rexml/security.rb +27 -0
- data/lib/rexml/source.rb +95 -50
- data/lib/rexml/streamlistener.rb +90 -90
- data/lib/rexml/syncenumerator.rb +3 -4
- data/lib/rexml/text.rb +157 -76
- data/lib/rexml/validation/relaxng.rb +18 -18
- data/lib/rexml/validation/validation.rb +5 -5
- data/lib/rexml/xmldecl.rb +59 -63
- data/lib/rexml/xmltokens.rb +14 -14
- data/lib/rexml/xpath.rb +67 -53
- data/lib/rexml/xpath_parser.rb +49 -38
- data/lib/rubysl/rexml.rb +1 -0
- data/lib/rubysl/rexml/version.rb +1 -1
- data/rubysl-rexml.gemspec +3 -1
- metadata +19 -28
- data/lib/rexml/encodings/CP-1252.rb +0 -103
- data/lib/rexml/encodings/EUC-JP.rb +0 -35
- data/lib/rexml/encodings/ICONV.rb +0 -22
- data/lib/rexml/encodings/ISO-8859-1.rb +0 -7
- data/lib/rexml/encodings/ISO-8859-15.rb +0 -72
- data/lib/rexml/encodings/SHIFT-JIS.rb +0 -37
- data/lib/rexml/encodings/SHIFT_JIS.rb +0 -1
- data/lib/rexml/encodings/UNILE.rb +0 -34
- data/lib/rexml/encodings/US-ASCII.rb +0 -30
- data/lib/rexml/encodings/UTF-16.rb +0 -35
- data/lib/rexml/encodings/UTF-8.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2dcb560e63dac60be850a3109d1f5775b5847b2
|
4
|
+
data.tar.gz: 8e6659caa5224404cdeeb2c039dc051b2eeae6f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5cab30fb1725a2107ab2fa15bf6027c7bfae1282105a74a09f1ca004b63a1d5f68c6351b1da78d5753e7935c6f40f9d82c06f5796820718d4cfeb054eb53ebe
|
7
|
+
data.tar.gz: edbd1a851942e68796deef805874ff3415b5fb8e67be7246e13477ab2f96bcf404d08310f37a1dfb32c1c0528b01ffce94f9fb485950bc147bca7081c5e08dc4
|
data/.travis.yml
CHANGED
data/lib/rexml/attlistdecl.rb
CHANGED
@@ -3,60 +3,60 @@ require 'rexml/child'
|
|
3
3
|
require 'rexml/source'
|
4
4
|
|
5
5
|
module REXML
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
6
|
+
# This class needs:
|
7
|
+
# * Documentation
|
8
|
+
# * Work! Not all types of attlists are intelligently parsed, so we just
|
9
|
+
# spew back out what we get in. This works, but it would be better if
|
10
|
+
# we formatted the output ourselves.
|
11
|
+
#
|
12
|
+
# AttlistDecls provide *just* enough support to allow namespace
|
13
|
+
# declarations. If you need some sort of generalized support, or have an
|
14
|
+
# interesting idea about how to map the hideous, terrible design of DTD
|
15
|
+
# AttlistDecls onto an intuitive Ruby interface, let me know. I'm desperate
|
16
|
+
# for anything to make DTDs more palateable.
|
17
|
+
class AttlistDecl < Child
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
# What is this? Got me.
|
21
|
+
attr_reader :element_name
|
22
|
+
|
23
|
+
# Create an AttlistDecl, pulling the information from a Source. Notice
|
24
|
+
# that this isn't very convenient; to create an AttlistDecl, you basically
|
25
|
+
# have to format it yourself, and then have the initializer parse it.
|
26
|
+
# Sorry, but for the forseeable future, DTD support in REXML is pretty
|
27
|
+
# weak on convenience. Have I mentioned how much I hate DTDs?
|
28
|
+
def initialize(source)
|
29
|
+
super()
|
30
|
+
if (source.kind_of? Array)
|
31
|
+
@element_name, @pairs, @contents = *source
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Access the attlist attribute/value pairs.
|
36
|
+
# value = attlist_decl[ attribute_name ]
|
37
|
+
def [](key)
|
38
|
+
@pairs[key]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Whether an attlist declaration includes the given attribute definition
|
42
|
+
# if attlist_decl.include? "xmlns:foobar"
|
43
|
+
def include?(key)
|
44
|
+
@pairs.keys.include? key
|
45
|
+
end
|
46
|
+
|
47
|
+
# Iterate over the key/value pairs:
|
48
|
+
# attlist_decl.each { |attribute_name, attribute_value| ... }
|
49
|
+
def each(&block)
|
50
|
+
@pairs.each(&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Write out exactly what we got in.
|
54
|
+
def write out, indent=-1
|
55
|
+
out << @contents
|
56
|
+
end
|
57
|
+
|
58
|
+
def node_type
|
59
|
+
:attlistdecl
|
60
|
+
end
|
61
|
+
end
|
62
62
|
end
|
data/lib/rexml/attribute.rb
CHANGED
@@ -2,168 +2,174 @@ require "rexml/namespace"
|
|
2
2
|
require 'rexml/text'
|
3
3
|
|
4
4
|
module REXML
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
5
|
+
# Defines an Element Attribute; IE, a attribute=value pair, as in:
|
6
|
+
# <element attribute="value"/>. Attributes can be in their own
|
7
|
+
# namespaces. General users of REXML will not interact with the
|
8
|
+
# Attribute class much.
|
9
|
+
class Attribute
|
10
|
+
include Node
|
11
|
+
include Namespace
|
12
|
+
|
13
|
+
# The element to which this attribute belongs
|
14
|
+
attr_reader :element
|
15
|
+
# The normalized value of this attribute. That is, the attribute with
|
16
|
+
# entities intact.
|
17
|
+
attr_writer :normalized
|
18
|
+
PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
|
19
|
+
|
20
|
+
NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um
|
21
|
+
|
22
|
+
# Constructor.
|
21
23
|
# FIXME: The parser doesn't catch illegal characters in attributes
|
22
24
|
#
|
23
|
-
# first::
|
25
|
+
# first::
|
24
26
|
# Either: an Attribute, which this new attribute will become a
|
25
27
|
# clone of; or a String, which is the name of this attribute
|
26
28
|
# second::
|
27
29
|
# If +first+ is an Attribute, then this may be an Element, or nil.
|
28
30
|
# If nil, then the Element parent of this attribute is the parent
|
29
|
-
# of the +first+ Attribute. If the first argument is a String,
|
30
|
-
# then this must also be a String, and is the content of the attribute.
|
31
|
+
# of the +first+ Attribute. If the first argument is a String,
|
32
|
+
# then this must also be a String, and is the content of the attribute.
|
31
33
|
# If this is the content, it must be fully normalized (contain no
|
32
34
|
# illegal characters).
|
33
35
|
# parent::
|
34
|
-
# Ignored unless +first+ is a String; otherwise, may be the Element
|
36
|
+
# Ignored unless +first+ is a String; otherwise, may be the Element
|
35
37
|
# parent of this attribute, or nil.
|
36
38
|
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
39
|
+
#
|
40
|
+
# Attribute.new( attribute_to_clone )
|
41
|
+
# Attribute.new( attribute_to_clone, parent_element )
|
42
|
+
# Attribute.new( "attr", "attr_value" )
|
43
|
+
# Attribute.new( "attr", "attr_value", parent_element )
|
44
|
+
def initialize( first, second=nil, parent=nil )
|
45
|
+
@normalized = @unnormalized = @element = nil
|
46
|
+
if first.kind_of? Attribute
|
47
|
+
self.name = first.expanded_name
|
48
|
+
@unnormalized = first.value
|
49
|
+
if second.kind_of? Element
|
50
|
+
@element = second
|
51
|
+
else
|
52
|
+
@element = first.element
|
53
|
+
end
|
54
|
+
elsif first.kind_of? String
|
55
|
+
@element = parent
|
56
|
+
self.name = first
|
57
|
+
@normalized = second.to_s
|
58
|
+
else
|
59
|
+
raise "illegal argument #{first.class.name} to Attribute constructor"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the namespace of the attribute.
|
64
|
+
#
|
65
|
+
# e = Element.new( "elns:myelement" )
|
66
|
+
# e.add_attribute( "nsa:a", "aval" )
|
67
|
+
# e.add_attribute( "b", "bval" )
|
68
|
+
# e.attributes.get_attribute( "a" ).prefix # -> "nsa"
|
69
|
+
# e.attributes.get_attribute( "b" ).prefix # -> "elns"
|
70
|
+
# a = Attribute.new( "x", "y" )
|
71
|
+
# a.prefix # -> ""
|
72
|
+
def prefix
|
73
|
+
pf = super
|
74
|
+
if pf == ""
|
75
|
+
pf = @element.prefix if @element
|
76
|
+
end
|
77
|
+
pf
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the namespace URL, if defined, or nil otherwise
|
81
|
+
#
|
82
|
+
# e = Element.new("el")
|
83
|
+
# e.add_namespace("ns", "http://url")
|
84
|
+
# e.add_attribute("ns:a", "b")
|
85
|
+
# e.add_attribute("nsx:a", "c")
|
86
|
+
# e.attribute("ns:a").namespace # => "http://url"
|
87
|
+
# e.attribute("nsx:a").namespace # => nil
|
88
|
+
def namespace arg=nil
|
89
|
+
arg = prefix if arg.nil?
|
90
|
+
@element.namespace arg
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns true if other is an Attribute and has the same name and value,
|
94
|
+
# false otherwise.
|
95
|
+
def ==( other )
|
96
|
+
other.kind_of?(Attribute) and other.name==name and other.value==value
|
97
|
+
end
|
98
|
+
|
99
|
+
# Creates (and returns) a hash from both the name and value
|
100
|
+
def hash
|
101
|
+
name.hash + value.hash
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns this attribute out as XML source, expanding the name
|
105
|
+
#
|
106
|
+
# a = Attribute.new( "x", "y" )
|
107
|
+
# a.to_string # -> "x='y'"
|
108
|
+
# b = Attribute.new( "ns:x", "y" )
|
109
|
+
# b.to_string # -> "ns:x='y'"
|
110
|
+
def to_string
|
111
|
+
if @element and @element.context and @element.context[:attribute_quote] == :quote
|
112
|
+
%Q^#@expanded_name="#{to_s().gsub(/"/, '"e;')}"^
|
113
|
+
else
|
114
|
+
"#@expanded_name='#{to_s().gsub(/'/, ''')}'"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def doctype
|
119
|
+
if @element
|
120
|
+
doc = @element.document
|
121
|
+
doc.doctype if doc
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Returns the attribute value, with entities replaced
|
126
|
+
def to_s
|
127
|
+
return @normalized if @normalized
|
128
|
+
|
129
|
+
@normalized = Text::normalize( @unnormalized, doctype )
|
130
|
+
@unnormalized = nil
|
125
131
|
@normalized
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
doc = @element.document
|
135
|
-
doctype = doc.doctype if doc
|
136
|
-
end
|
137
|
-
@unnormalized = Text::unnormalize( @normalized, doctype )
|
138
|
-
@normalized = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
# Returns the UNNORMALIZED value of this attribute. That is, entities
|
135
|
+
# have been expanded to their values
|
136
|
+
def value
|
137
|
+
return @unnormalized if @unnormalized
|
138
|
+
@unnormalized = Text::unnormalize( @normalized, doctype )
|
139
|
+
@normalized = nil
|
139
140
|
@unnormalized
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
141
|
+
end
|
142
|
+
|
143
|
+
# Returns a copy of this attribute
|
144
|
+
def clone
|
145
|
+
Attribute.new self
|
146
|
+
end
|
147
|
+
|
148
|
+
# Sets the element of which this object is an attribute. Normally, this
|
149
|
+
# is not directly called.
|
150
|
+
#
|
151
|
+
# Returns this attribute
|
152
|
+
def element=( element )
|
153
|
+
@element = element
|
154
|
+
|
155
|
+
if @normalized
|
156
|
+
Text.check( @normalized, NEEDS_A_SECOND_CHECK, doctype )
|
157
|
+
end
|
158
|
+
|
159
|
+
self
|
160
|
+
end
|
161
|
+
|
162
|
+
# Removes this Attribute from the tree, and returns true if successfull
|
163
|
+
#
|
164
|
+
# This method is usually not called directly.
|
165
|
+
def remove
|
166
|
+
@element.attributes.delete self.name unless @element.nil?
|
167
|
+
end
|
168
|
+
|
169
|
+
# Writes this attribute (EG, puts 'key="value"' to the output)
|
170
|
+
def write( output, indent=-1 )
|
171
|
+
output << to_string
|
172
|
+
end
|
167
173
|
|
168
174
|
def node_type
|
169
175
|
:attribute
|
@@ -180,6 +186,6 @@ module REXML
|
|
180
186
|
path += "/@#{self.expanded_name}"
|
181
187
|
return path
|
182
188
|
end
|
183
|
-
|
189
|
+
end
|
184
190
|
end
|
185
191
|
#vim:ts=2 sw=2 noexpandtab:
|