@@ -110,13 +110,9 @@ struct Node <: AbstractXMLNode
110110 isnothing (attributes) ? nothing : Dict (string (k) => string (v) for (k, v) in pairs (attributes)),
111111 isnothing (value) ? nothing : string (value),
112112 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))
120116 )
121117 end
122118end
@@ -193,8 +189,10 @@ parent(o) = missing
193189next (o) = missing
194190prev (o) = missing
195191
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]
197194
195+ simplevalue (o) = is_simple (o) ? value (only (o)) : error (" `XML.simplevalue(o)` is only defined for simple nodes." )
198196
199197# -----------------------------------------------------------------------------# nodes_equal
200198function nodes_equal (a, b)
@@ -220,6 +218,8 @@ Base.lastindex(o::Union{Raw, AbstractXMLNode}) = lastindex(children(o))
220218
221219Base. only (o:: Union{Raw, AbstractXMLNode} ) = only (children (o))
222220
221+ Base. length (o:: AbstractXMLNode ) = length (children (o))
222+
223223# -----------------------------------------------------------------------------# printing
224224function _show_node (io:: IO , o)
225225 ! ismissing (depth (o)) && print (io, depth (o), ' :' )
@@ -281,7 +281,8 @@ write(x; kw...) = (io = IOBuffer(); write(io, x; kw...); String(take!(io)))
281281
282282write (filename:: AbstractString , x; kw... ) = open (io -> write (io, x; kw... ), filename, " w" )
283283
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
285286 nodetype = XML. nodetype (x)
286287 tag = XML. tag (x)
287288 value = XML. value (x)
@@ -298,12 +299,12 @@ function write(io::IO, x; indent = " ", depth=depth(x))
298299 print (io, isempty (children) ? ' /' : " " , ' >' )
299300 if ! isempty (children)
300301 if length (children) == 1 && XML. nodetype (only (children)) === Text
301- write (io, only (children); indent = " " )
302+ write (io, only (children); indentsize = 0 )
302303 print (io, " </" , tag, ' >' )
303304 else
304305 println (io)
305306 foreach (children) do child
306- write (io, child; indent )
307+ write (io, child; indentsize, depth = depth + 1 )
307308 println (io)
308309 end
309310 print (io, padding, " </" , tag, ' >' )
@@ -325,7 +326,7 @@ function write(io::IO, x; indent = " ", depth=depth(x))
325326 print (io, " <![CData[" , value, " ]]>" )
326327 elseif nodetype === Document
327328 foreach (children) do child
328- write (io, child; indent )
329+ write (io, child; indentsize )
329330 println (io)
330331 end
331332 else
0 commit comments