@@ -110,13 +110,9 @@ struct Node <: AbstractXMLNode
110
110
isnothing (attributes) ? nothing : Dict (string (k) => string (v) for (k, v) in pairs (attributes)),
111
111
isnothing (value) ? nothing : string (value),
112
112
isnothing (children) ? nothing :
113
- children isa Vector{Node} ? children : begin
114
- if any (x -> ! (x isa Node), children)
115
- Base. depwarn (" Providing non-Node children to a Node is deprecated. " *
116
- " All provided children have been changed to Text(input)" , :Node ; force= true )
117
- end
118
- map (Node, collect (children))
119
- end
113
+ children isa Vector{Node} ? children :
114
+ children isa Vector ? map (Node, children) :
115
+ map (Node, collect (children))
120
116
)
121
117
end
122
118
end
@@ -193,8 +189,10 @@ parent(o) = missing
193
189
next (o) = missing
194
190
prev (o) = missing
195
191
196
- nodeinfo (o) = (; nodetype= nodetype (o), tag= tag (o), attributes= attributes (o), value= value (o), depth= depth (o))
192
+ is_simple (o) = nodetype (o) == Element && (isnothing (attributes (o)) || isempty (attributes (o))) &&
193
+ length (children (o)) == 1 && nodetype (only (o)) in [Text, CData]
197
194
195
+ simplevalue (o) = is_simple (o) ? value (only (o)) : error (" `XML.simplevalue(o)` is only defined for simple nodes." )
198
196
199
197
# -----------------------------------------------------------------------------# nodes_equal
200
198
function nodes_equal (a, b)
@@ -220,6 +218,8 @@ Base.lastindex(o::Union{Raw, AbstractXMLNode}) = lastindex(children(o))
220
218
221
219
Base. only (o:: Union{Raw, AbstractXMLNode} ) = only (children (o))
222
220
221
+ Base. length (o:: AbstractXMLNode ) = length (children (o))
222
+
223
223
# -----------------------------------------------------------------------------# printing
224
224
function _show_node (io:: IO , o)
225
225
! ismissing (depth (o)) && print (io, depth (o), ' :' )
@@ -281,7 +281,8 @@ write(x; kw...) = (io = IOBuffer(); write(io, x; kw...); String(take!(io)))
281
281
282
282
write (filename:: AbstractString , x; kw... ) = open (io -> write (io, x; kw... ), filename, " w" )
283
283
284
- function write (io:: IO , x; indent = " " , depth= depth (x))
284
+ function write (io:: IO , x; indentsize:: Int = 2 , depth:: Union{Missing,Int} = depth (x))
285
+ indent = ' ' ^ indentsize
285
286
nodetype = XML. nodetype (x)
286
287
tag = XML. tag (x)
287
288
value = XML. value (x)
@@ -298,12 +299,12 @@ function write(io::IO, x; indent = " ", depth=depth(x))
298
299
print (io, isempty (children) ? ' /' : " " , ' >' )
299
300
if ! isempty (children)
300
301
if length (children) == 1 && XML. nodetype (only (children)) === Text
301
- write (io, only (children); indent = " " )
302
+ write (io, only (children); indentsize = 0 )
302
303
print (io, " </" , tag, ' >' )
303
304
else
304
305
println (io)
305
306
foreach (children) do child
306
- write (io, child; indent )
307
+ write (io, child; indentsize, depth = depth + 1 )
307
308
println (io)
308
309
end
309
310
print (io, padding, " </" , tag, ' >' )
@@ -325,7 +326,7 @@ function write(io::IO, x; indent = " ", depth=depth(x))
325
326
print (io, " <![CData[" , value, " ]]>" )
326
327
elseif nodetype === Document
327
328
foreach (children) do child
328
- write (io, child; indent )
329
+ write (io, child; indentsize )
329
330
println (io)
330
331
end
331
332
else
0 commit comments