gravitext-xmlprod 1.5.1-java → 1.6.0-java
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/History.rdoc
CHANGED
data/Manifest.txt
CHANGED
@@ -54,6 +54,14 @@ module Gravitext::XMLProd
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
# Return Array of descendant elements matching tag and/or where
|
58
|
+
# yielding to block returns true. Elements failing the tag/block
|
59
|
+
# test will be recursed into, in search of more matches.
|
60
|
+
def select_r( tag = nil, &block )
|
61
|
+
tag = Tag.new( tag, Tag.WILDCARD_NS ) unless tag.nil? || tag.is_a?( Tag )
|
62
|
+
_select_r( [], tag, block || TRUTH )
|
63
|
+
end
|
64
|
+
|
57
65
|
# Return first child element matching tag and/or where yielding to
|
58
66
|
# block returns true. Without a block is equivalent to
|
59
67
|
# first_element.
|
@@ -68,6 +76,15 @@ module Gravitext::XMLProd
|
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
79
|
+
# Return first descendant element matching the specified tag
|
80
|
+
# and/or where yielding to block returns true. Elements failing
|
81
|
+
# the tag/block test will be recursed into, in search of the first
|
82
|
+
# match.
|
83
|
+
def find_r( tag = nil, &block )
|
84
|
+
tag = Tag.new( tag, Tag.WILDCARD_NS ) unless tag.nil? || tag.is_a?( Tag )
|
85
|
+
_find_r( tag, block || TRUTH )
|
86
|
+
end
|
87
|
+
|
71
88
|
# Serialize self to String of XML, with options.
|
72
89
|
def to_xml( opts = {} )
|
73
90
|
XMLHelper.write_element( self,
|
@@ -75,6 +92,33 @@ module Gravitext::XMLProd
|
|
75
92
|
opts[ :qmark ] || QuoteMark::DOUBLE,
|
76
93
|
opts[ :implied_ns ] || [] )
|
77
94
|
end
|
95
|
+
|
96
|
+
def _find_r( tag, pred )
|
97
|
+
children.each do |c|
|
98
|
+
if c.element?
|
99
|
+
found = c if ( tag.nil? || c.tag == tag ) && pred.call( c )
|
100
|
+
found ||= c._find_r( tag, pred )
|
101
|
+
return found if found
|
102
|
+
end
|
103
|
+
end
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
def _select_r( matches, tag, pred )
|
108
|
+
children.each do |c|
|
109
|
+
if c.element?
|
110
|
+
if ( tag.nil? || c.tag == tag ) && pred.call( c )
|
111
|
+
matches << c
|
112
|
+
else
|
113
|
+
c._select_r( matches, tag, pred )
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
matches
|
118
|
+
end
|
119
|
+
|
120
|
+
TRUTH = lambda { |e| true }
|
121
|
+
|
78
122
|
end
|
79
123
|
|
80
124
|
end
|
Binary file
|
data/pom.xml
CHANGED
data/test/test_tree.rb
CHANGED
@@ -160,6 +160,33 @@ XML
|
|
160
160
|
assert_equal( 1, root.select { |e| e[ att ] == 'a2value' }.length )
|
161
161
|
end
|
162
162
|
|
163
|
+
def test_recurse
|
164
|
+
xml = <<XML
|
165
|
+
<doc>
|
166
|
+
<o1 a='1'>
|
167
|
+
<i1>text</i1>
|
168
|
+
<i2>next</i2>
|
169
|
+
</o1>
|
170
|
+
<o1 a='2'/>
|
171
|
+
<o1>
|
172
|
+
<o2>
|
173
|
+
<i1 a='3'>other</i1>
|
174
|
+
<i3/>
|
175
|
+
</o2>
|
176
|
+
</o1>
|
177
|
+
</doc>
|
178
|
+
XML
|
179
|
+
root = parse_tree( xml )
|
180
|
+
|
181
|
+
assert_equal( 'text', root.find_r( 'i1' ).characters )
|
182
|
+
assert_equal( 'next', root.find_r( 'i2' ).characters )
|
183
|
+
assert_equal( 'other',
|
184
|
+
root.find_r( 'i1' ) { |e| e['a'] == '3' }.characters )
|
185
|
+
|
186
|
+
assert_equal( %w[ 1 2 3 ],
|
187
|
+
root.select_r { |e| e['a'] }.map { |e| e['a'] } )
|
188
|
+
end
|
189
|
+
|
163
190
|
def test_invalid_xml_error
|
164
191
|
assert_raises( XMLStreamException ) do
|
165
192
|
parse_tree( "<doc><open></doc>" )
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gravitext-xmlprod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.6.0
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- David Kellum
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-23 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gravitext-util
|
@@ -81,7 +81,7 @@ files:
|
|
81
81
|
- test/test_dom.rb
|
82
82
|
- test/test_tree.rb
|
83
83
|
- test/xml/huffingtonpost.full.atom.xml
|
84
|
-
- lib/gravitext-xmlprod/gravitext-xmlprod-1.
|
84
|
+
- lib/gravitext-xmlprod/gravitext-xmlprod-1.6.0.jar
|
85
85
|
homepage: http://gravitext.rubyforge.org
|
86
86
|
licenses: []
|
87
87
|
|