I found that if I don't go into child nodes then it doesn't assert: but then it
doesn't go through the XML file either! Here's a modified `write` that still
asserts:
proc write(file: File, node: XmlNode, indent: int) =
if indent > 0:
file.write(spaces(indent))
file.write(&"<{node.tag}")
let attrs = node.attrs()
if attrs != nil:
for (key, value) in attrs.pairs():
file.write(&" {key}=\"{value}\"")
file.write(">")
if node.kind != xnElement and node.text != "":
file.write(node.text)
if len(node) > 0:
for child in node:
write(file, child, indent + INDENT)
file.write(&"</{node.tag}>\n")
Run
I tried commenting out the attrs code and the node.text code but that didn't
help.
SOLVED: The problem was with the signature. Even though I don't (knowingly)
modify any nodes, changing the signature's `node: XmlNode` to `node: var
XmlNode` cured the assertion error.