您的位置:首页 > 其它

pugixml 学习笔记一 加载文件

2014-01-24 18:27 423 查看
编程环境 VC 6.0

// pugixmltest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
//可以是相对路径,或者绝对路径
bool LoadFromFile(const char * szXmlFileName)
{
pugi::xml_document doc;

pugi::xml_parse_result result = doc.load_file(szXmlFileName);

std::cout << "Load result: " << result.description() <<std::endl
<< "name.attrib = " << doc.child("Name").attribute("age").value() << std::endl;

return true;
}

bool LoadFromBuffer()
{

const char *szBuffer="<?xml version=\"1.0\"?><Name age=\"10\">good</Name>";
pugi::xml_document doc;
if (!doc.load_buffer(szBuffer,strlen(szBuffer)))
return false;

std::cout<< "name.attrib = " << doc.child("Name").attribute("age").value() << std::endl;
return true;

}
bool LoadFromMem()
{
const char *szBuffer="<?xml version=\"1.0\"?><Name age=\"10\">good</Name>";
pugi::xml_document doc;
if (!doc.load(szBuffer))
return false;

std::cout<< "name.attrib = " << doc.child("Name").attribute("age").value() << std::endl;
return true;
}
bool LoadFromStream()
{
std::ifstream stream("tree.xml");
pugi::xml_document doc;
if (!doc.load(stream))
{
return false;
}
std::cout<< "name.attrib = " << doc.child("Name").attribute("age").value() << std::endl;
return true;
}

int main(int argc, char* argv[])
{
//LoadFromFile("tree.xml");
//LoadFromBuffer();
//LoadFromMem();
LoadFromStream();
return 0;
}


代码下载地址: http://download.csdn.net/detail/u012607841/6881367
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: