1
- export addelm !
1
+ export addnode !
2
2
# ###############################################################
3
3
# Add node
4
4
# ###############################################################
5
5
# Document
6
6
# ###############################################################
7
7
# Any
8
8
"""
9
- addelm !(node, name, value, argAmlType)
9
+ addnode !(node, name, value, argAmlType)
10
10
11
- Add one element to a node/document
11
+ To add nodes (single or a vector of nodes) as a child of given a node/document.
12
12
"""
13
- function addelm ! (aml:: Document , name:: String , value:: T , argAmlType:: Type{<:AbsDocOrNode} ) where {T}
13
+ function addnode ! (aml:: Document , name:: String , value:: T , argAmlType:: Type{<:AbsDocOrNode} ) where {T}
14
14
15
15
if hasroot (aml)
16
16
amlNode = root (aml)
17
- elm = addelm ! (amlNode, name, value, argAmlType)
17
+ elm = addnode ! (amlNode, name, value, argAmlType)
18
18
return elm
19
19
elseif hasfield (T, :aml )
20
20
elm = setroot! (aml, value. aml)
@@ -26,22 +26,22 @@ function addelm!(aml::Document, name::String, value::T, argAmlType::Type{<:AbsDo
26
26
end
27
27
28
28
# Nothing
29
- function addelm ! (aml:: Document , name:: String , value:: Nothing , argAmlType:: Type{<:AbsDocOrNode} )
29
+ function addnode ! (aml:: Document , name:: String , value:: Nothing , argAmlType:: Type{<:AbsDocOrNode} )
30
30
# do nothing if value is nothing
31
31
end
32
32
# ###############################################################
33
33
# Vector
34
34
"""
35
- addelm !(node, name, value, argAmlType)
35
+ addnode !(node, name, value, argAmlType)
36
36
37
37
Add a vector to a node/document
38
38
```
39
39
"""
40
- function addelm ! (aml:: Document , name:: String , value:: Vector , argAmlType:: Type{<:AbsDocOrNode} )
40
+ function addnode ! (aml:: Document , name:: String , value:: Vector , argAmlType:: Type{<:AbsDocOrNode} )
41
41
42
42
if hasroot (aml)
43
43
amlNode = root (aml)
44
- elm = addelm ! (amlNode, name, value, argAmlType)
44
+ elm = addnode ! (amlNode, name, value, argAmlType)
45
45
return elm
46
46
else
47
47
error (" You cannot insert a vector in the document directly. Define a @aml defined field for xml or html document struct" )
53
53
# Nodes
54
54
# ###############################################################
55
55
# String
56
- @transform function addelm ! (aml:: Node , name:: String ,value:: AbstractString , argAmlType:: Type{allsubtypes(AbsNormal)} )
56
+ @transform function addnode ! (aml:: Node , name:: String ,value:: AbstractString , argAmlType:: Type{allsubtypes(AbsNormal)} )
57
57
if ! isnothing (value) # do nothing if value is nothing
58
58
elm = addelement! (aml, name, value)
59
59
return elm
60
60
end
61
61
end
62
62
63
- function addelm ! (aml:: Node , name:: String ,value:: AbstractString , argAmlType:: Type{AbsAttribute} )
63
+ function addnode ! (aml:: Node , name:: String ,value:: AbstractString , argAmlType:: Type{AbsAttribute} )
64
64
if ! isnothing (value) # do nothing if value is nothing
65
65
elm = link! (aml, AttributeNode (name, value))
66
66
return elm
67
67
end
68
68
end
69
69
70
- function addelm ! (aml:: Node , indexstr:: String ,value:: AbstractString , argAmlType:: Type{AbsText} )
70
+ function addnode ! (aml:: Node , indexstr:: String ,value:: AbstractString , argAmlType:: Type{AbsText} )
71
71
index = parse_textindex (indexstr)
72
72
if index < length (elements (aml))
73
73
desired_node = elements (aml)[index]
@@ -85,21 +85,21 @@ function addelm!(aml::Node, indexstr::String,value::AbstractString, argAmlType::
85
85
end
86
86
87
87
# Number (and also Bool <:Number)
88
- @transform function addelm ! (aml:: Node , name:: String , value:: Number , argAmlType:: Type{allsubtypes(AbsNormal)} )
88
+ @transform function addnode ! (aml:: Node , name:: String , value:: Number , argAmlType:: Type{allsubtypes(AbsNormal)} )
89
89
if ! isnothing (value) # do nothing if value is nothing
90
90
elm = addelement! (aml, name, string (value))
91
91
return elm
92
92
end
93
93
end
94
94
95
- function addelm ! (aml:: Node , name:: String , value:: Number , argAmlType:: Type{AbsAttribute} )
95
+ function addnode ! (aml:: Node , name:: String , value:: Number , argAmlType:: Type{AbsAttribute} )
96
96
if ! isnothing (value) # do nothing if value is nothing
97
97
elm = link! (aml, AttributeNode (name, string (value)))
98
98
return elm
99
99
end
100
100
end
101
101
102
- function addelm ! (aml:: Node , indexstr:: String , value:: Number , argAmlType:: Type{AbsText} )
102
+ function addnode ! (aml:: Node , indexstr:: String , value:: Number , argAmlType:: Type{AbsText} )
103
103
index = parse_textindex (indexstr)
104
104
if index < length (elements (aml))
105
105
desired_node = elements (aml)[index]
@@ -117,7 +117,7 @@ function addelm!(aml::Node, indexstr::String, value::Number, argAmlType::Type{Ab
117
117
end
118
118
119
119
# Other
120
- function addelm ! (aml:: Node , name:: String , value:: T , argAmlType:: Type{<:AbsNormal} ) where {T}
120
+ function addnode ! (aml:: Node , name:: String , value:: T , argAmlType:: Type{<:AbsNormal} ) where {T}
121
121
if hasfield (T, :aml )
122
122
elm = link! (aml,value. aml)
123
123
return elm
@@ -137,7 +137,7 @@ function addelm!(aml::Node, name::String, value::T, argAmlType::Type{<:AbsNormal
137
137
end
138
138
end
139
139
140
- function addelm ! (aml:: Node , name:: String , value:: T , argAmlType:: Type{AbsAttribute} ) where {T}
140
+ function addnode ! (aml:: Node , name:: String , value:: T , argAmlType:: Type{AbsAttribute} ) where {T}
141
141
if hasfield (T, :aml )
142
142
elm = link! (aml, AttributeNode (name, value. aml))
143
143
return elm
@@ -157,7 +157,7 @@ function addelm!(aml::Node, name::String, value::T, argAmlType::Type{AbsAttribut
157
157
end
158
158
end
159
159
160
- function addelm ! (aml:: Node , indexstr:: String , value:: T , argAmlType:: Type{AbsText} ) where {T}
160
+ function addnode ! (aml:: Node , indexstr:: String , value:: T , argAmlType:: Type{AbsText} ) where {T}
161
161
index = parse_textindex (indexstr)
162
162
if index < length (elements (aml))
163
163
@@ -203,31 +203,31 @@ function addelm!(aml::Node, indexstr::String, value::T, argAmlType::Type{AbsText
203
203
end
204
204
205
205
# Nothing
206
- @transform function addelm ! (aml:: Node , name:: String , value:: Nothing , argAmlType:: Type{allsubtypes(AbsDocOrNode)} )
206
+ @transform function addnode ! (aml:: Node , name:: String , value:: Nothing , argAmlType:: Type{allsubtypes(AbsDocOrNode)} )
207
207
# do nothing
208
208
end
209
209
# ###############################################################
210
210
# Vector
211
211
212
212
allsubtypes_butAbsText (t) = setdiff (allsubtypes (AbsDocOrNode), [AbsText])
213
213
214
- @transform function addelm ! (aml:: Node , name:: String , values:: Vector , argAmlType:: Type{allsubtypes_butAbsText(AbsDocOrNode)} )
214
+ @transform function addnode ! (aml:: Node , name:: String , values:: Vector , argAmlType:: Type{allsubtypes_butAbsText(AbsDocOrNode)} )
215
215
elms = Vector {Union{Node, Nothing}} (undef, length (values))
216
216
for (ielm, value) in enumerate (values)
217
- elms[ielm] = addelm ! (aml, name, value, argAmlType)
217
+ elms[ielm] = addnode ! (aml, name, value, argAmlType)
218
218
end
219
219
return elms
220
220
end
221
221
222
- function addelm ! (aml:: Node , indicesstr:: String , values:: Vector , argAmlType:: Type{AbsText} )
222
+ function addnode ! (aml:: Node , indicesstr:: String , values:: Vector , argAmlType:: Type{AbsText} )
223
223
indices = parse_textindices (indicesstr)
224
224
if indices isa Colon
225
225
indices = 1 : length (elements (aml))
226
226
end
227
227
elms = Vector {Union{Node, Nothing}} (undef, length (indices))
228
228
ielm = 1
229
229
for (value, index) in zip (values, indices)
230
- elms[ielm] = addelm ! (aml, string (index), value, argAmlType)
230
+ elms[ielm] = addnode ! (aml, string (index), value, argAmlType)
231
231
ielm += 1
232
232
end
233
233
return elms
@@ -236,14 +236,14 @@ end
236
236
# ###############################################################
237
237
# Dict
238
238
239
- @transform function addelm ! (aml:: Node , name:: String , values:: AbstractDict , argAmlType:: Type{allsubtypes(AbsDocOrNode)} )
239
+ @transform function addnode ! (aml:: Node , name:: String , values:: AbstractDict , argAmlType:: Type{allsubtypes(AbsDocOrNode)} )
240
240
# name is discarded now: actual names are stored in the Dict itself
241
241
# elements are added directly
242
242
# for AbsText, v_name is considered as the text index
243
243
elms = Vector {Union{Node, Nothing}} (undef, length (values))
244
244
ielm = 1
245
245
for (v_name, v_value) in values
246
- elms[ielm] = addelm ! (aml, v_name, v_value, argAmlType)
246
+ elms[ielm] = addnode ! (aml, v_name, v_value, argAmlType)
247
247
ielm += 1
248
248
end
249
249
end
0 commit comments