Hello, I am very new to Nim and recently discovered it. I thought it might be
cool to generate an XML file for my app cast updater. I seem to misunderstand
or there is bug when I am trying to nest with indentation.
Format exmple:
# <xml header>
# <rss>
# <channel>
# <title>
# <description>
# <item>
# <title><title/>
# <sparkle><sparkle/>
# <pub date><pub date/>
# <enclosure/>
# </item>
# </channel>
# </rss>
Run
Code example:
# item tree
########################################################################################
var t = newElement("title")
t.add newText("Version")
var sr = newElement("sparkle:releaseNotesLink")
sr.add newText("some url to the release notes")
var pd = newElement("pubDate")
pd.add newText("the date")
var enc = newElement("enclosure")
let repo = "https://my-repo/"
let sV = "1.0"
let eAttr = {"url": repo, "sparkle:version": sV}.toXmlAttributes
enc.attrs = eAttr
let itemTree = newXmlTree("item", [t, sr, pd, enc])
# channel tree
#####################################################################################
var title = newElement("title")
title.add newText("My App Title")
var description = newElement("description")
description.add newText("For GUI updates")
let channelTree = newXmlTree("channel", [title, description, itemTree])
# rss tree
#########################################################################################
let namespace = "http://www.andymatuschak.org/xml-namespaces/sparkle"
let elements = "http://purl.org/dc/elements/1.1/"
let v = "2.0"
let nsAtt = {"xmlns:sparkle": namespace, "xmlns:dc": elements, "version":
v}.toXmlAttributes
let rssTree = newXmlTree("rss", [channelTree], nsAtt)
# output to file
###################################################################################
echo rssTree
let f = open("test.xml", fmWrite)
try:
write(f, xmlHeader & $rssTree)
finally:
f.close()
Run
Output:
<rss version="2.0"
xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"
xmlns:dc="http://purl.org/dc/elements/1.1/"><channel>
<title>My App Title</title>
<description>For GUI updates</description>
<item>
<title>Version</title>
<sparkle:releaseNotesLink>some url to the release
notes</sparkle:releaseNotesLink>
<pubDate>the date</pubDate>
<enclosure sparkle:version="1.0" url="https://my-repo/" />
</item>
</channel></rss>
Run
I am expecting the
<channel>
Run
element to be on its own line indented. I am also expecting the end
</rss>
Run
to be on its own line as well.
I am not sure where I am going wrong. If anyone has any tips it would be
greatly appreciated. Thank you kindly!