• 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>

  • 相关阅读:
    Linux_9/ RAID & LVM
    Linux_8/ fdisk, xfs_quota, edquota
    Linux_7/(chattr, lsattr), (setfacl, getfacl),su
    Linux_6/ Vim, Shell(下),(at, crond), (SUID, SGID, SBIT)
    Linux_5/ Vim, Shell(上)
    Linux_4/ |, (>, 2>, &>, >>, 2>>)
    Map集合的遍历
    List集合三种遍历方法
    MySQL安装
    排序法
  • 原文地址:https://www.cnblogs.com/cy568searchx/p/2845274.html
Copyright © 2020-2023  润新知