第一部分不是对您问题的直接回答,但我将继续您的句子“我以前从未使用过 XML”。由于当今 XML 在计算中的流行,花一些时间来了解 XML 的工作原理是值得的。对于直接参考,我推荐 Harold 和 Means 的“XML in a Nutshell”。它解释了 XML、模式(准确定义传入的 XML 必须是什么样子)、XPath(如何导航节点以获取所需的数据)、XQuery、XSLT、名称空间等。
真正对您有所帮助的是概念,为此您可能需要另一本书(抱歉,我没有可推荐的书。)了解为什么应该以正确的方式使用 XML 很重要,而不仅仅是将其视为一个美化的 .INI 文件。为什么 DOM 概念很流行。您是否应该使用 SAX。
Probably the most relevant things to learn are XML schemas (XSDs). While it sometimes seems like overkill, you should strongly consider validating your XML against its schema (which is a one-method-call to a full XML parser such as xerces.) Remember, this is 2009, your program is running on a computer with a lot of memory, and it can do most of that stuff really, really fast; so it's totally worth it to know your data is good. And once you understand schemas, I'd recommend learning how to version them. That's especially important when dealing with program storage, because you can then make your programs understand previous versions of saved files and use or upgrade them automatically.
To more directly answer your immediate question, use TinyXML (or whatever parser you choose) for writing. Don't reinvent the output wheel when you already have the tool in hand.