Poco库之XML操作

平台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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值