@@ -111,7 +111,7 @@ iterator tokens*(input: string): XmlToken {.inline.} =
111111 inc (pos)
112112 var next_ch = input.find (ch, pos)
113113 if next_ch == - 1 :
114- error (fmt" unable to find matching string quote last found { pos} " )
114+ error (fmt" unable to find matching string quote last found { pos} " )
115115 yield token (STRING , input[pos..< next_ch])
116116 pos = next_ch+ 1
117117 of '>' :
@@ -167,7 +167,7 @@ proc newNode(name: string, text = ""): XmlNode =
167167proc child * (node: XmlNode , name: string ): XmlNode =
168168 # # finds the first element of `node` with name `name`
169169 # # returns `nil` on failure
170- if not node.children.isNil :
170+ if node.children.len > 0 :
171171 for n in node.children:
172172 if n.name == name:
173173 result = n
@@ -179,22 +179,22 @@ proc `$`*(node: XmlNode): string =
179179 if not node.attributes.isNil:
180180 for k, v in node.attributes.pairs:
181181 result .add (fmt" { k} ="" { v} "" " )
182- if node.text.len == 0 and node.children.isNil :
182+ if node.text.len == 0 and node.children.len == 0 :
183183 result .add (" />" )
184184 return
185185 elif node.text.len > 0 :
186186 result .add (" >" & node.text)
187187 else :
188188 result .add (" >" )
189189
190- if not node.children.isNil :
190+ if node.children.len > 0 :
191191 for child in node.children:
192192 result .add ($ child)
193193 result .add (" </" & node.name & " >" )
194194
195195
196196proc addChild * (node, child: XmlNode ) =
197- if node.children.isNil :
197+ if node.children.len == 0 :
198198 node.children = @ []
199199 node.children.add (child)
200200
@@ -302,7 +302,3 @@ when isMainModule:
302302
303303 assert class1.children[3 ].hasAttr (" type" )
304304 assert class1.children[3 ].attr (" type" ) == " Date"
305-
306-
307-
308-
0 commit comments