XML API functions

All commits from pull requests #4 and #5 merged into a single beautiful commit.