zoukankan      html  css  js  c++  java
  • 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

    生活的残酷,让我们习惯了忘记疲倦,一直奔向远方,追寻着自己的梦想。
  • 相关阅读:
    手机号码正则表达式
    POJ 3233 Matrix Power Series 矩阵快速幂
    UVA 11468
    UVA 1449
    HDU 2896 病毒侵袭 AC自动机
    HDU 3065 病毒侵袭持续中 AC自动机
    HDU 2222 Keywords Search AC自动机
    POJ 3461 Oulipo KMP模板题
    POJ 1226 Substrings KMP
    UVA 1455 Kingdom 线段树+并查集
  • 原文地址:https://www.cnblogs.com/L-Arikes/p/4772422.html
Copyright © 2011-2022 走看看