xml-motor 0.1.5 → 0.1.6
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/CHANGELOG +4 -0
- data/README +12 -0
- data/lib/xml-motor.rb +16 -0
- data/lib/xml-motor/version.rb +1 -1
- data/lib/xml-motor/xml-motor-engine.rb +37 -5
- data/lib/xml-motor/xml-utils.rb +1 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -7,6 +7,10 @@
|
|
7
7
|
=====================================================================
|
8
8
|
CHANGE-LOG
|
9
9
|
=====================================================================
|
10
|
+
Changes from v0.1.5 to v0.1.6
|
11
|
+
[] XMLMotor.xmlattrib to fetch attribute values from XML
|
12
|
+
[] fixing attrib value infection for db-quote
|
13
|
+
=====================================================================
|
10
14
|
Changes from v0.1.4 to v0.1.5
|
11
15
|
[] Fixed grep for nodes like "<splitline color='green'/>"
|
12
16
|
[] Fetch nodes with ATTRIB_KEY for a/all node by not giving its ATTRIB_VALUE
|
data/README
CHANGED
@@ -27,6 +27,18 @@ An easy-to-use XML Parser without any Native Dependencies.
|
|
27
27
|
+ 'require' the 'xml-motor'
|
28
28
|
|
29
29
|
Usage:
|
30
|
+
[[ To Fetch Just Attribute Values ]]
|
31
|
+
str = {XML_DATA}
|
32
|
+
nodes_ = XMLMotor.splitter str
|
33
|
+
tags_ = XMLMotor.splitter nodes_
|
34
|
+
XMLMotor.xmlattrib 'attrib_to_fetch_value', nodes_, tags_
|
35
|
+
XMLMotor.xmlattrib 'attrib_to_fetch_value', nodes_, tags_, <_TAG_>
|
36
|
+
XMLMotor.xmlattrib 'attrib_to_fetch_value', nodes_, tags_, <_TAG_>, "ATTRIB_KEY"
|
37
|
+
XMLMotor.xmlattrib 'attrib_to_fetch_value', nodes_, tags_, <_TAG_>, "ATTRIB_KEY="
|
38
|
+
XMLMotor.xmlattrib 'attrib_to_fetch_value', nodes_, tags_, <_TAG_>, "ATTRIB_KEY=ATTRIB_VALUE"
|
39
|
+
XMLMotor.xmlattrib 'attrib_to_fetch_value', nodes_, tags_, <_TAG_>, "=ATTRIB_VALUE"
|
40
|
+
|
41
|
+
|
30
42
|
[[ To Search More Than One QUERIES ]]
|
31
43
|
str = {XML_DATA}
|
32
44
|
nodes_ = XMLMotor.splitter str
|
data/lib/xml-motor.rb
CHANGED
@@ -35,4 +35,20 @@ module XMLMotor
|
|
35
35
|
def self.xmldata(nodes, tags=nil, tag_to_find=nil, attrib_to_find=nil, with_tag=false)
|
36
36
|
XMLMotorEngine.pre_processed_content nodes, tags, tag_to_find, attrib_to_find, with_tag
|
37
37
|
end
|
38
|
+
|
39
|
+
def self.xmlattrib(attrib_key, nodes, tags=nil, tag_to_find=nil, attrib_to_find=nil)
|
40
|
+
unless tag_to_find.nil? && attrib_to_find.nil?
|
41
|
+
attribs = XMLMotorEngine.pre_processed_content nodes, tags, tag_to_find, attrib_to_find, false, attrib_key
|
42
|
+
else
|
43
|
+
attribs = XMLMotorEngine.pre_processed_content nodes, tags, tag_to_find, attrib_key, false, attrib_key
|
44
|
+
end
|
45
|
+
attribs = attribs.collect{|attrib|
|
46
|
+
if attrib.match(/^"(.*)"$/).nil?
|
47
|
+
attrib
|
48
|
+
else
|
49
|
+
attrib[1..-2].gsub('\"','"')
|
50
|
+
end
|
51
|
+
}
|
52
|
+
return attribs
|
53
|
+
end
|
38
54
|
end
|
data/lib/xml-motor/version.rb
CHANGED
@@ -62,7 +62,7 @@ module XMLMotorEngine
|
|
62
62
|
node_start = index_to_find[ncount*2]
|
63
63
|
node_stop = index_to_find[ncount*2 +1]
|
64
64
|
unless attrib_to_find.nil? or attrib_to_find.empty?
|
65
|
-
|
65
|
+
next if @xmlnodes[node_start][0][1].nil?
|
66
66
|
check_keyval = attrib_keyval.collect{|keyval| @xmlnodes[node_start][0][1][keyval.first] == keyval.last}.include? false
|
67
67
|
check_key = attrib_justkey.collect{|key| @xmlnodes[node_start][0][1][key.first].nil? }.include? true
|
68
68
|
check_val = attrib_justval.collect{|val| @xmlnodes[node_start][0][1].each_value.include? val[1] }.include? false
|
@@ -85,7 +85,35 @@ module XMLMotorEngine
|
|
85
85
|
nodes
|
86
86
|
end
|
87
87
|
|
88
|
-
def self.
|
88
|
+
def self._grab_my_attrib_ (attrib_key, index_to_find, attrib_to_find=nil)
|
89
|
+
unless attrib_to_find.nil? or attrib_to_find.empty?
|
90
|
+
attrib_keyval = [attrib_to_find].flatten.collect{|keyval| _get_attrib_key_val_ keyval }
|
91
|
+
attrib_justkey = attrib_keyval.select{|attr| attr[1].empty?}
|
92
|
+
attrib_justval = attrib_keyval.select{|attr| attr[0].empty?}
|
93
|
+
attrib_keyval -= (attrib_justkey + attrib_justval)
|
94
|
+
end
|
95
|
+
|
96
|
+
attribs = []
|
97
|
+
node_count = index_to_find.size/2 - 1
|
98
|
+
0.upto node_count do |ncount|
|
99
|
+
node_start = index_to_find[ncount*2]
|
100
|
+
node_stop = index_to_find[ncount*2 +1]
|
101
|
+
unless attrib_to_find.nil? or attrib_to_find.empty?
|
102
|
+
next if @xmlnodes[node_start][0][1].nil?
|
103
|
+
check_keyval = attrib_keyval.collect{|keyval| @xmlnodes[node_start][0][1][keyval.first] == keyval.last}.include? false
|
104
|
+
check_key = attrib_justkey.collect{|key| @xmlnodes[node_start][0][1][key.first].nil? }.include? true
|
105
|
+
check_val = attrib_justval.collect{|val| @xmlnodes[node_start][0][1].each_value.include? val[1] }.include? false
|
106
|
+
next if check_keyval or check_key or check_val
|
107
|
+
end
|
108
|
+
unless @xmlnodes[node_start][0][1].nil?
|
109
|
+
attribs[ncount] = @xmlnodes[node_start][0][1][attrib_key] unless @xmlnodes[node_start][0][1][attrib_key].nil?
|
110
|
+
end
|
111
|
+
end
|
112
|
+
attribs.delete(nil) unless attrib_to_find.nil?
|
113
|
+
attribs
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.xml_extracter(tag_to_find=nil, attrib_to_find=nil, with_tag=false, just_attrib_val=nil)
|
89
117
|
index_to_find = []
|
90
118
|
if attrib_to_find.nil? and tag_to_find.nil?
|
91
119
|
return nil
|
@@ -94,7 +122,11 @@ module XMLMotorEngine
|
|
94
122
|
else
|
95
123
|
index_to_find = XMLIndexHandler.get_tag_indexes self, tag_to_find.downcase
|
96
124
|
end
|
97
|
-
|
125
|
+
if just_attrib_val.nil?
|
126
|
+
return _grab_my_node_ index_to_find, attrib_to_find, with_tag
|
127
|
+
else
|
128
|
+
return _grab_my_attrib_ just_attrib_val, index_to_find, attrib_to_find
|
129
|
+
end
|
98
130
|
end
|
99
131
|
|
100
132
|
def self.xml_miner(xmldata, tag_to_find=nil, attrib_to_find=nil, with_tag=false)
|
@@ -112,7 +144,7 @@ module XMLMotorEngine
|
|
112
144
|
@xmltags = xml_tags || @xmltags
|
113
145
|
end
|
114
146
|
|
115
|
-
def self.pre_processed_content(_nodes, _tags=nil, tag_to_find=nil, attrib_to_find=nil, with_tag=false)
|
147
|
+
def self.pre_processed_content(_nodes, _tags=nil, tag_to_find=nil, attrib_to_find=nil, with_tag=false, just_attrib_val=nil)
|
116
148
|
begin
|
117
149
|
xmlnodes _nodes
|
118
150
|
unless _tags.nil?
|
@@ -120,7 +152,7 @@ module XMLMotorEngine
|
|
120
152
|
else
|
121
153
|
_indexify_
|
122
154
|
end
|
123
|
-
return xml_extracter tag_to_find, attrib_to_find, with_tag
|
155
|
+
return xml_extracter tag_to_find, attrib_to_find, with_tag, just_attrib_val
|
124
156
|
rescue
|
125
157
|
XMLStdout._err "Parsing processed XML Nodes."
|
126
158
|
end
|
data/lib/xml-motor/xml-utils.rb
CHANGED
@@ -3,7 +3,7 @@ module XMLUtils
|
|
3
3
|
return nil if attrib_val.nil?
|
4
4
|
matched_data = attrib_val.strip.match(/^'(.*)'$/)
|
5
5
|
return attrib_val if matched_data.nil?
|
6
|
-
matched_data = matched_data[0].gsub("\"","
|
6
|
+
matched_data = matched_data[0].gsub("\"","\\\"")
|
7
7
|
matched_data[0] = matched_data[-1] = "\""
|
8
8
|
matched_data
|
9
9
|
end
|
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.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'A new short XML Parsing Algorithm implemented directly in less-than-500
|
15
15
|
lines. An easy-to-use XML Parser without any Native Dependencies. Its under continuous
|