zoukankan      html  css  js  c++  java
  • TinyXML解析器 入门

    //初始化:建立XML结构文件 ,创建根节点

    TiXmlDocument *myDocument = new TiXmlDocument("ePhoto.xml");

           TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", "" );

          myDocument->LinkEndChild(decl);

             TiXmlElement *ephoto=new TiXmlElement("ephoto");

          myDocument->LinkEndChild(ephoto);

           myDocument->SaveFile("ePhoto.xml");//保存

    //打开已经建立的XML结构文件,对其进行操作。

    TiXmlDocument *myDocument = new TiXmlDocument("ePhoto.xml");

    myDocument->LoadFile();//载入文件

    //增加节点

    TiXmlElement *type1 = new TiXmlElement(type);//“type1”是字符串变量

    TiXmlElement *type2 = new TiXmlElement("photo");

     type2->SetAttribute("ID","1");

    myDocument->FirstChildElement()->LinkEndChild(type1); type1->LinkEndChild(type2);

    //删除节点

    TiXmlNode *node=first1;

    myDocument->FirstChildElement()->RemoveChild(node);

    //更新节点

    TiXmlText te1(s);

    xmlp->ReplaceChild(xmlp->FirstChild(),te1);

    xmlp=xmlp->NextSiblingElement();

    ///////////////////////////////////////////////////////////////////////

    xml结构文件ePhoto.xml如下:

    <?xml version="1.0" encoding="UTF-8" ?>

    <ephoto>

        <Andy>

            <photo ID="1">

                <name>NULL</name>

                <directory>NULL</directory>

                <describe>NULL</describe>

            </photo>

        </Andy>

        <Tom>

            <photo ID="1">

                <name>NULL</name>

                <directory>NULL</directory>

                <describe>NULL</describe>

            </photo>

        </Tom>

        <Bill>

            <photo ID="1">

                <name>NULL</name>

                <directory>NULL</directory>

                <describe>NULL</describe>

            </photo>

        </Bill>

    </ephoto>

  • 相关阅读:
    Codeforces 每日一练 1213G+961E+1282B2
    AtCoder Beginner Contest 161题解
    Codeforces每日一练 495B+55C+1280C
    CF1062E 线段树/LCA
    Codeforces Round #697 (Div. 3) 题解
    Codeforces Round #511 (Div. 2) A~D题解
    Atcoder ABC 189 题解
    CF1093G 高维曼哈顿距离/线段树
    CF1117D Magic Gems 矩阵快速幂 DP
    CF1106E Lunar New Year and Red Envelopes DP
  • 原文地址:https://www.cnblogs.com/cy568searchx/p/2845274.html
Copyright © 2011-2022 走看看