xml-motor 0.0.7 → 0.0.8
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/README +15 -1
- data/lib/xml-motor.rb +21 -12
- data/lib/xml-motor/version.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
//\\ || || ||_ || || ||_|| || ||_|| ||\\
|
5
5
|
|
6
6
|
======================================================================
|
7
|
-
v 0.0.
|
7
|
+
v 0.0.8
|
8
8
|
|
9
9
|
@GitHub: https://github.com/abhishekkr/rubygem_xml_motor
|
10
10
|
@RubyGems: http://rubygems.org/gems/xml-motor
|
@@ -32,12 +32,18 @@ An easy-to-use XML Parser without any Native Dependencies.
|
|
32
32
|
nodes_array = XMLMotor.get_node_from_file "_XML_FILE_", "ATTRIB_KEY=ATTRIB_VALUE"
|
33
33
|
nodes_array = XMLMotor.get_node_from_content "_XML_DATA_"
|
34
34
|
nodes_array = XMLMotor.get_node_from_content "_XML_DATA_", "ATTRIB_KEY=ATTRIB_VALUE"
|
35
|
+
>>>>> for having root-node-tag also in returned result <<<<<
|
36
|
+
nodes_array = XMLMotor.get_node_from_file "_XML_FILE_", nil, true
|
37
|
+
nodes_array = XMLMotor.get_node_from_content "_XML_DATA_", "ATTRIB_KEY=ATTRIB_VALUE", true
|
35
38
|
[[ To Search More Than One QUERIES ]]
|
36
39
|
str = {XML_DATA}
|
37
40
|
nodes_ = XMLMotorEngine._splitter_ str
|
38
41
|
tags_ = XMLMotorEngine._indexify_ nodes_
|
39
42
|
nodes_array = XMLMotorEngine.pre_processed_content nodes_, tags_, "_TAG_"
|
40
43
|
nodes_array = XMLMotorEngine.pre_processed_content nodes_, tags_, "_TAG_", "ATTRIB_KEY=ATTRIB_VALUE"
|
44
|
+
>>>>> for having root-node-tag also in returned result <<<<<
|
45
|
+
nodes_array = XMLMotorEngine.pre_processed_content nodes_, tags_, "_TAG_", nil, true
|
46
|
+
nodes_array = XMLMotorEngine.pre_processed_content nodes_, tags_, "_TAG_", "ATTRIB_KEY=ATTRIB_VALUE", true
|
41
47
|
|
42
48
|
Example Calls As Code:
|
43
49
|
+ XMLMotor.get_node_from_content "<A>a</A><B><A>ba</A></B>", "A"
|
@@ -51,6 +57,14 @@ An easy-to-use XML Parser without any Native Dependencies.
|
|
51
57
|
=====================================================================
|
52
58
|
CHANGE-LOG
|
53
59
|
=====================================================================
|
60
|
+
Changes from v0.0.7 to v0.0.8
|
61
|
+
[] avail the result inclusive of root-node-value with an extra 'true' after attrib/nil
|
62
|
+
for e.g.
|
63
|
+
XMLMotor.get_node_from_content "<a><b id=\"2\">a.b</b></a>", "b", nil, true
|
64
|
+
XMLMotor.get_node_from_content "<a><b id=\"2\">a.b</b></a>", "b", "id='2'", true
|
65
|
+
both of above would give
|
66
|
+
["<b id=\"2\">a.b</b>"]
|
67
|
+
=====================================================================
|
54
68
|
Changes from v0.0.6 to v0.0.7
|
55
69
|
[] correcting the attribute matching to be sensitive to single and double quotes
|
56
70
|
=====================================================================
|
data/lib/xml-motor.rb
CHANGED
@@ -97,6 +97,11 @@ module XMLJoiner
|
|
97
97
|
end
|
98
98
|
attributes
|
99
99
|
end
|
100
|
+
|
101
|
+
def self.dejavu_node(node_block)
|
102
|
+
return nil if node_block.nil?
|
103
|
+
["<#{node_block.first}#{dejavu_attributes(node_block.last)}>", "</#{node_block.first}>"]
|
104
|
+
end
|
100
105
|
end
|
101
106
|
|
102
107
|
##
|
@@ -133,7 +138,7 @@ module XMLMotorEngine
|
|
133
138
|
@xmltags
|
134
139
|
end
|
135
140
|
|
136
|
-
def self._grab_my_node_ (xml_to_find, attrib_to_find=nil)
|
141
|
+
def self._grab_my_node_ (xml_to_find, attrib_to_find=nil, with_tag=false)
|
137
142
|
unless attrib_to_find.nil?
|
138
143
|
attrib_key = attrib_to_find.split(/=/)[0].strip
|
139
144
|
attrib_val = attrib_to_find.split(/=/)[1..-1].join.strip
|
@@ -155,33 +160,37 @@ module XMLMotorEngine
|
|
155
160
|
nodes[ncount] += "<" + @xmlnodes[node_idx][0][0] + any_attrib + ">"
|
156
161
|
nodes[ncount] += @xmlnodes[node_idx][1] unless @xmlnodes[node_idx][1].nil?
|
157
162
|
end
|
163
|
+
if with_tag
|
164
|
+
tagifyd = XMLJoiner.dejavu_node @xmlnodes[node_start][0]
|
165
|
+
nodes[ncount] = tagifyd.first + nodes[ncount] + tagifyd.last
|
166
|
+
end
|
158
167
|
end
|
159
168
|
nodes.delete(nil) unless attrib_to_find.nil?
|
160
169
|
nodes
|
161
170
|
end
|
162
171
|
|
163
|
-
def self.xml_extracter(tag_to_find=nil, attrib_to_find=nil)
|
172
|
+
def self.xml_extracter(tag_to_find=nil, attrib_to_find=nil, with_tag=false)
|
164
173
|
my_nodes = nil
|
165
174
|
if attrib_to_find.nil? and tag_to_find.nil?
|
166
175
|
elsif attrib_to_find.nil?
|
167
176
|
xml_to_find = XMLIndexHandler.get_node_indexes self, tag_to_find
|
168
|
-
my_nodes = _grab_my_node_ xml_to_find
|
177
|
+
my_nodes = _grab_my_node_ xml_to_find, nil, with_tag
|
169
178
|
elsif tag_to_find.nil?
|
170
179
|
#
|
171
180
|
XMLStdout._nfo "Just attrib-based search to come"
|
172
181
|
#
|
173
182
|
else
|
174
183
|
xml_to_find = XMLIndexHandler.get_node_indexes self, tag_to_find
|
175
|
-
my_nodes = _grab_my_node_ xml_to_find, attrib_to_find
|
184
|
+
my_nodes = _grab_my_node_ xml_to_find, attrib_to_find, with_tag
|
176
185
|
end
|
177
186
|
my_nodes
|
178
187
|
end
|
179
188
|
|
180
|
-
def self.xml_miner(xmldata, tag_to_find=nil, attrib_to_find=nil)
|
189
|
+
def self.xml_miner(xmldata, tag_to_find=nil, attrib_to_find=nil, with_tag=false)
|
181
190
|
return nil if xmldata.nil?
|
182
191
|
_splitter_ xmldata
|
183
192
|
_indexify_
|
184
|
-
xml_extracter tag_to_find, attrib_to_find
|
193
|
+
xml_extracter tag_to_find, attrib_to_find, with_tag
|
185
194
|
end
|
186
195
|
|
187
196
|
def self.xmlnodes(xml_nodes=nil)
|
@@ -194,7 +203,7 @@ module XMLMotorEngine
|
|
194
203
|
@xmltags
|
195
204
|
end
|
196
205
|
|
197
|
-
def self.pre_processed_content(_nodes, _tags=nil, tag_to_find=nil, attrib_to_find=nil)
|
206
|
+
def self.pre_processed_content(_nodes, _tags=nil, tag_to_find=nil, attrib_to_find=nil, with_tag=false)
|
198
207
|
begin
|
199
208
|
xmlnodes _nodes
|
200
209
|
unless _tags.nil?
|
@@ -202,7 +211,7 @@ module XMLMotorEngine
|
|
202
211
|
else
|
203
212
|
_indexify_
|
204
213
|
end
|
205
|
-
return xml_extracter tag_to_find, attrib_to_find
|
214
|
+
return xml_extracter tag_to_find, attrib_to_find, with_tag
|
206
215
|
rescue
|
207
216
|
XMLStdout._err "Parsing processed XML Nodes."
|
208
217
|
end
|
@@ -214,18 +223,18 @@ end
|
|
214
223
|
# XMLMotor_EXECUTIONER ;)
|
215
224
|
|
216
225
|
module XMLMotor
|
217
|
-
def self.get_node_from_file(file, my_tag=nil, my_attrib=nil)
|
226
|
+
def self.get_node_from_file(file, my_tag=nil, my_attrib=nil, with_tag=false)
|
218
227
|
begin
|
219
|
-
return get_node_from_content(File.read(file.to_s), my_tag, my_attrib) if File.readable? file.to_s
|
228
|
+
return get_node_from_content(File.read(file.to_s), my_tag, my_attrib, with_tag) if File.readable? file.to_s
|
220
229
|
rescue
|
221
230
|
XMLStdout._err "#{file} is not readable."
|
222
231
|
end
|
223
232
|
return ""
|
224
233
|
end
|
225
234
|
|
226
|
-
def self.get_node_from_content(content, my_tag=nil, my_attrib=nil)
|
235
|
+
def self.get_node_from_content(content, my_tag=nil, my_attrib=nil, with_tag=false)
|
227
236
|
begin
|
228
|
-
return XMLMotorEngine.xml_miner content, my_tag, my_attrib unless content.nil?
|
237
|
+
return XMLMotorEngine.xml_miner content, my_tag, my_attrib, with_tag unless content.nil?
|
229
238
|
rescue
|
230
239
|
XMLStdout._err "Parsing String Content #{content}"
|
231
240
|
end
|
data/lib/xml-motor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml-motor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abhishekkr
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-16 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|