I'm writing a Lua application that generates an Atom feed. Right now, I'm generating XML "by hand" -- writing strings to files.

This doesn't seem like the best way, although it may be. I am getting nervous about having the escaping exactly right. Has anyone done anything like this in Lua before? 

Should I stick with generating "by hand"? Or write a wrapper for an existing C library?

(Perl, by comparison, seems to have [a plethora of options](https://stackoverflow.com/questions/1137790/how-can-i-escape-text-for-an-xml-document-in-perl).)