tinyxml xml文件添加节点信息

tinyxml xml文件添加节点信息

 

 1  // 获取xml文件路径
 2  CString sXmlPath  =  CCommonFun::GetExecutablePath()  +   " 420120223165116971.pcl.xml " ;
 3   
 4  TiXmlDocument *  pXmlDoc  =   new  TiXmlDocument(sXmlPath);
 5  // 导入xml文件
 6  pXmlDoc -> LoadFile();
 7 
 8  // 获取根节点
 9  TiXmlElement  * xmlRootElement  =  pXmlDoc -> RootElement();
10 
11  // 创建新节点
12  TiXmlElement  * x1  =   new  TiXmlElement( " WaterMarks " );
13  xmlRootElement -> LinkEndChild(x1);
14 
15  // 创建新节点下的子节点
16  TiXmlElement  * nameElement  =   new  TiXmlElement( " WaterMark " );
17  // 设置子节点属性
18  nameElement -> SetAttribute( " copies " " 1 " );
19  nameElement -> SetAttribute( " type " " 1 " );
20 
21  // 创建新节点下的子节点
22  TiXmlElement  * ageElement  =   new  TiXmlElement( " WaterMark " );
23  ageElement -> SetAttribute( " copies " " 2 " );
24  ageElement -> SetAttribute( " type " " 1 " );
25  x1 -> LinkEndChild(nameElement);
26  x1 -> LinkEndChild(ageElement);
27 
28           //   TiXmlText *nameContent = new TiXmlText("aaa");
29           //      TiXmlText *ageContent = new TiXmlText("12");
30          //   nameElement->LinkEndChild(nameContent);
31          //   ageElement->LinkEndChild(ageContent);
32 
33  // 保存xml文件
34   pXmlDoc -> SaveFile(sXmlPath);

 

你可能感兴趣的:(tinyxml xml文件添加节点信息)