TinyXML 2 in Terminal
来源:互联网 发布:最新韩国网络剧2017 编辑:程序博客网 时间:2024/06/06 01:53
- 测试说明
- 测试代码
- 终端编译
测试说明
- 在源文件目录下放置tinyxml2.cpp和tinyxml.h文件
- 测试文件TinyXMLTest.cpp
测试代码
#include <iostream>#include <string>#include "tinyxml2.h"using namespace tinyxml2;void makeXML(const char *_fileName){ // use absulote path std::string filePath = std::string("/Users/phenix/Desktop/") + _fileName; XMLDocument *pDoc = new XMLDocument(); // xml declaration XMLDeclaration *pDel = pDoc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\""); pDoc->LinkEndChild(pDel); // add 'plist' node XMLElement *plistElement = pDoc->NewElement("plist"); plistElement->SetAttribute("version", "1.0"); pDoc->LinkEndChild(plistElement); // Add a child node as the last (right) child. XMLComment *commentElement = pDoc->NewComment("this is xml comment"); plistElement->LinkEndChild(commentElement); // add 'dic' node XMLElement *dicElement = pDoc->NewElement("dic"); plistElement->LinkEndChild(dicElement); // add 'key' node XMLElement *keyElement = pDoc->NewElement("key"); keyElement->LinkEndChild(pDoc->NewText("Text")); dicElement->LinkEndChild(keyElement); XMLElement *arrayElement = pDoc->NewElement("array"); dicElement->LinkEndChild(arrayElement); for (int i = 0; i<3; i++) { XMLElement *elm = pDoc->NewElement("name"); elm->LinkEndChild(pDoc->NewText("Cocos2d-x")); arrayElement->LinkEndChild(elm); } pDoc->SaveFile(filePath.c_str()); pDoc->Print(); delete pDoc; // <?xml version="1.0" encoding="UTF-8"?> // <plist version="1.0"> // <!--this is xml comment--> // <dic> // <key>Text</key> // <array> // <name>Cocos2d-x</name> // <name>Cocos2d-x</name> // <name>Cocos2d-x</name> // </array> // </dic> // </plist>}void parseXML(const char *_fileName){ // std::string filePath = FileUtils::getInstance()->getWritablePath() + _fileName; // use absolute path std::string filePath = std::string("/Users/phenix/Desktop/") + _fileName; XMLDocument *pDoc = new XMLDocument(); XMLError errorId = pDoc->LoadFile(filePath.c_str()); if (errorId != 0) { // xml format error return; } XMLElement *rootEle = pDoc->RootElement(); // get the first node's attribute const XMLAttribute *attribute = rootEle->FirstAttribute(); // print the node's attribute and value std::cout << "attribute_name = " << attribute->Name() << ",attribute_value = " << attribute->Value() << std::endl; XMLElement *dicEle = rootEle->FirstChildElement("dic"); XMLElement *keyEle = dicEle->FirstChildElement("key"); if (keyEle) { std::cout << "keyEle Text = " << keyEle->GetText() << std::endl; } XMLElement *arrayEle = keyEle->NextSiblingElement(); XMLElement *childEle = arrayEle->FirstChildElement(); while ( childEle ) { std::cout << "childEle Text = " << childEle->GetText() << std::endl; childEle = childEle->NextSiblingElement(); } delete pDoc;}int main(int argc, char const *argv[]){ makeXML("Example.xml"); parseXML("Example.xml"); return 0;}
终端编译
g++ -std=c++11 TinyXMLTest.cpp tinyxml2.cpp
CSDN 辣鸡 MD 编辑器,无序列表格式全丢
阅读全文
0 0
- TinyXML 2 in Terminal
- virtual terminal in SXCE
- Run terminal script in Finder
- Install "Open Terminal" in Ubuntu
- Open Terminal Here in Ubuntu
- change dir color in terminal
- no terminal colors in Linux
- TinyXML开源XML解析器-TinyXML-2
- TinyXml使用指南(2)
- TinyXml快速入门2
- TinyXML-2使用
- tinyxml学习2
- Tinyxml-2源码学习
- TinyXml-2 Tutorial 中文翻译
- tinyXML
- tinyxml
- TinyXml
- tinyxml
- 元数据分类
- 使用wine初始化wine32环境
- iOS 笔试题04~[有答案]
- Linux--高级I/O多路复用之epoll
- 整数排序 II
- TinyXML 2 in Terminal
- ARP协议及应用
- 算法题目-魔力手环
- U3D中的特殊文件夹摘要
- 毕业两年
- Apache 2.2.32编译安装
- 前端开发正则表达式验证以及常用的正则表达式
- 反射和内省
- JavaEE学习13--Jquery