1
- export findalllocal, findfirstlocal, findtext, findtextloacl, findvecttextlocal
2
1
# ###############################################################
3
- # Searchers Utils
2
+ # Utilities
3
+ # ###############################################################
4
+ function Base. get (node:: Node , name:: String , defval)
5
+ if haskey (node, name)
6
+ return node[name]
7
+ else
8
+ return defval
9
+ end
10
+ end
11
+ # ###############################################################
12
+
13
+ """
14
+ findfirstatt(name, node)
15
+
16
+ Finds the first attribute with `name`
17
+
18
+ findfirst with ignoring namespaces. It considers att.name for returning the elements
19
+
20
+ Much faster than EzXML.findfirst
21
+ """
22
+ function findfirstatt (name:: String , node:: Node )
23
+ out = nothing # return nothing if nothing is found
24
+ for att in eachattribute (node)
25
+ if att. name == name
26
+ out = att
27
+ break
28
+ end
29
+ end
30
+ return out
31
+ end
32
+
33
+ """
34
+ findallatt(string, node)
35
+
36
+ Finds all the attributes with `name`
37
+
38
+ findallatt with ignoring namespaces. It considers att.name for returning the elements
39
+
40
+ Much faster than EzXML.findall
41
+ """
42
+ function findallatt (name:: String , node:: Node )
43
+ out = Node[]
44
+ for att in eachattribute (node)
45
+ if att. name == name
46
+ push! (out, att)
47
+ end
48
+ end
49
+ if ! isempty (out)
50
+ return out
51
+ else # return nothing if nothing is found
52
+ return nothing
53
+ end
54
+ end
55
+
56
+
4
57
# ###############################################################
5
58
# Local searchers (no namespace)
6
59
"""
7
- findfirstlocal (string, node)
60
+ findfirstelm (string, node)
8
61
9
62
findfirst with ignoring namespaces. It considers element.name for returning the elements
10
63
11
64
Much faster than EzXML.findfirst
12
65
"""
13
- function findfirstlocal (name:: String , node:: Node )
66
+ function findfirstelm (name:: String , node:: Node )
14
67
out = nothing # return nothing if nothing is found
15
68
for child in eachelement (node)
16
69
if child. name == name
@@ -22,13 +75,13 @@ function findfirstlocal(name::String, node::Node)
22
75
end
23
76
24
77
"""
25
- findalllocal (string, node)
78
+ findallelm (string, node)
26
79
27
- findalllocal with ignoring namespaces. It considers element.name for returning the elements
80
+ findallelm with ignoring namespaces. It considers element.name for returning the elements
28
81
29
82
Much faster than EzXML.findall
30
83
"""
31
- function findalllocal (name:: String , node:: Node )
84
+ function findallelm (name:: String , node:: Node )
32
85
out = Node[]
33
86
for child in eachelement (node)
34
87
if child. name == name
@@ -42,6 +95,9 @@ function findalllocal(name::String, node::Node)
42
95
end
43
96
end
44
97
98
+ # ###############################################################
99
+ # Text node utils
100
+
45
101
function findtext (indexstr:: String , node:: Node )
46
102
if indexstr == " "
47
103
index = 1
@@ -83,13 +139,13 @@ function parse_textindex(indexstr::String)
83
139
end
84
140
85
141
"""
86
- findtextlocal (index::Integer, node)
142
+ findfirsttext (index::Integer, node)
87
143
88
144
finds the text node at position given by index.
89
145
90
146
faster than `findtext()`
91
147
"""
92
- function findtextlocal (index:: Integer , node:: Node )
148
+ function findfirsttext (index:: Integer , node:: Node )
93
149
iText = 0
94
150
out = nothing # return nothing if nothing is found
95
151
for child in eachnode (node)
@@ -103,7 +159,7 @@ function findtextlocal(index::Integer, node::Node)
103
159
end
104
160
return out
105
161
end
106
- function findtextlocal (index:: Float64 , node:: Node )
162
+ function findfirsttext (index:: Float64 , node:: Node )
107
163
if index != Inf
108
164
error (" index should be \" end\" " )
109
165
end
@@ -133,13 +189,13 @@ function parse_textindices(indicesstr::String)
133
189
end
134
190
135
191
"""
136
- findvecttextlocal (indices, node)
192
+ findalltext (indices, node)
137
193
138
194
finds the text node at positions given by indices.
139
195
140
196
faster than `findvecttext()`
141
197
"""
142
- function findvecttextlocal (indices:: Colon , node:: Node )
198
+ function findalltext (indices:: Colon , node:: Node )
143
199
out = Node[]
144
200
for child in eachnode (node)
145
201
if istext (child)
@@ -153,7 +209,7 @@ function findvecttextlocal(indices::Colon, node::Node)
153
209
end
154
210
end
155
211
156
- function findvecttextlocal (indices:: AbstractVector , node:: Node )
212
+ function findalltext (indices:: AbstractVector , node:: Node )
157
213
out = Node[]
158
214
iText = 0
159
215
for child in eachnode (node)
@@ -170,3 +226,5 @@ function findvecttextlocal(indices::AbstractVector, node::Node)
170
226
return nothing
171
227
end
172
228
end
229
+
230
+ # ###############################################################
0 commit comments