//初始化:建立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>

相关文章:

  • 2021-08-04
  • 2022-02-18
  • 2021-12-21
  • 2021-08-07
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
猜你喜欢
  • 2021-09-06
  • 2021-11-29
  • 2021-10-05
  • 2021-05-19
  • 2021-06-29
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案