一、用Poco库
Poco库是下载、编译和使用:www.cnblogs.com/htj10/p/11380144.html
DOM(The Document Object Model)方式:
1. 生成XML
#include <Poco/AutoPtr.h> #include <Poco/DOM/Document.h> //for Poco::XML::Document #include <Poco/DOM/Element.h> //for Poco::XML::Element #include <Poco/DOM/Text.h> //for Poco::XML::Text #include <Poco/DOM/CDATASection.h> //for Poco::XML::CDATASection #include <Poco/DOM/ProcessingInstruction.h> //for Poco::XML::ProcessingInstruction #include <Poco/DOM/Comment.h> //for Poco::XML::Comment #include <Poco/DOM/DOMWriter.h> //for Poco::XML::DOMWriter #include <Poco/XML/XMLWriter.h> //for Poco::XML::XMLWriter #include <sstream> int main(int argc, char** argv) { //Poco生成XML Poco::AutoPtr<Poco::XML::Document> pDoc = new Poco::XML::Document; Poco::AutoPtr<Poco::XML::ProcessingInstruction> pi = pDoc->createProcessingInstruction("xml","version='1.0' encoding='UTF-8'"); Poco::AutoPtr<Poco::XML::Comment> pComment = pDoc->createComment("The information of some Universities."