@@ -87,7 +87,7 @@ function showxml(io::IO, o::Node; depth=0)
8787 if isnothing (o. children)
8888 p (" />" )
8989 else
90- if length (o. children) == 1 && o. children[1 ] isa String
90+ if length (o. children) == 1 && o. children[1 ] isa String && ! occursin ( ' \n ' , o . children[ 1 ])
9191 p (' >' )
9292 showxml (io, o. children[1 ])
9393 p (" </" , o. tag, ' >' )
@@ -115,6 +115,24 @@ function Node(itr::XMLTokenIterator)
115115 return doc
116116end
117117
118+ function printnode (io:: IO , o:: Node )
119+ p (args... ) = print (io, args... )
120+ if o. type == DOCUMENT_NODE
121+ p (" DOCUMENT" )
122+ elseif o. type == DTD_NODE
123+ p (" <!doctype " , o. children, ' >' )
124+ elseif o. type == DECLARATION_NODE
125+ p (" <?" , o. tag, attr_string (o), " ?>" )
126+ elseif o. type == COMMENT_NODE
127+ p (" <!-- " , o. children, " -->" )
128+ elseif o. type == CDATA_NODE
129+ p (" <![CDATA[" , o. children, " ]]>" )
130+ elseif o. type == ELEMENT_NODE
131+ p (' <' , o. tag, attr_string (o))
132+ end
133+ o. type != DOCUMENT_NODE && p (' >' )
134+ end
135+ children (o:: Node ) = o. type in [ELEMENT_NODE, DOCUMENT_NODE] ? o. children : ()
118136
119137readnode (file:: String ) = open (io -> Node (XMLTokenIterator (io)), file, " r" )
120138
@@ -136,7 +154,7 @@ function add_children!(e::Node, o::XMLTokenIterator, until::String)
136154 add_children! (child, o, " </$(child. tag) >" )
137155 push! (c, child)
138156 elseif T == TEXTTOKEN
139- push! (c, unescape (s ))
157+ push! (c, unescape (rstrip (s) ))
140158 elseif T == DTDTOKEN
141159 push! (c, dtd (replace (s, " <!doctype " => " " , " <!DOCTYPE " => " " , ' >' => " " )))
142160 elseif T == DECLARATIONTOKEN
0 commit comments