加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Poco库之XML操作

发布时间:2020-12-16 08:49:14 所属栏目:百科 来源:网络整理
导读:平台ubuntu14.04LTS Poco版本:Poco1.6.1 #include Poco/DOM/Text.h #include Poco/DOM/Element.h #include Poco/DOM/Comment.h #include Poco/DOM/ProcessingInstruction.h #include Poco/DOM/Attr.h #include Poco/DOM/Document.h #include Poco/DOM/DOMWrit
平台ubuntu14.04LTS Poco版本:Poco1.6.1

#include <Poco/DOM/Text.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/Comment.h>
#include <Poco/DOM/ProcessingInstruction.h>
#include <Poco/DOM/Attr.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/DOMWriter.h>
#include <Poco/XML/XMLWriter.h>
#include <Poco/AutoPtr.h>
#include <Poco/FileStream.h>
using Poco::AutoPtr;
int main()
{
AutoPtr<Poco::XML::Document> pDoc = new Poco::XML::Document;
AutoPtr<Poco::XML::Element> myRoot = pDoc->createElement("Root");
AutoPtr<Poco::XML::Element> myChild = pDoc->createElement("Child");
AutoPtr<Poco::XML::Element> myGrandChild = pDoc->createElement("GrandChild");
AutoPtr<Poco::XML::Text> nameNode = pDoc->createTextNode("my_name_is_xiaoqiang");
AutoPtr<Poco::XML::ProcessingInstruction> pi = pDoc->createProcessingInstruction("xml","version='1.0' encoding='UTF-8'" );
AutoPtr<Poco::XML::Comment> comm = pDoc->createComment("new_day");

myGrandChild->appendChild(nameNode);
myChild->appendChild(myGrandChild);
myRoot->appendChild(myChild);
pDoc->appendChild(pi);
pDoc->appendChild(comm);
pDoc->appendChild(myRoot);

Poco::XML::DOMWriter write;

write.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT);
Poco::FileStream ofs("./example.txt",std::ios::in);
write.writeNode(ofs,pDoc);
return 0;
}
Notes:

LIBS += -lPocoFoundation -lPocoXML

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读