使用rapidxml从xml文件中读取指定项(建议两层)

来源:互联网 发布:php 闭包 use 多参数 编辑:程序博客网 时间:2024/06/05 09:45

2014年3月25日17:28:54

使用rapidxml从xml文件中读取指定项(建议两层)

1、使用VS2008创建一个带预编译头的控制台项目。

2、源文件内容:

#include "stdafx.h" #include<iostream>  using namespace std;#include "rapidxml.hpp"#include "rapidxml_utils.hpp"#include "rapidxml_print.hpp"using namespace rapidxml;int main(){file<> fdoc("lww.xml");xml_document<>   doc;doc.parse<0>(fdoc.data());char * str = NULL;xml_node<>* rootNode = doc.first_node("config");if(NULL == rootNode){printf("根结点不存在\n");system("PAUSE");return 1;}xml_node<>* colorNode = rootNode->first_node("color");if(NULL == colorNode){printf("color结点不存在\n");system("PAUSE");return 1;}xml_node<>* redNode = colorNode->first_node("red");if(NULL != redNode){str = redNode->value();if(NULL != str){printf("红色%s\n",str);}else{printf("值不存在\n");}}else{printf("red结点不存在\n");system("PAUSE");return 1;}system("PAUSE");return EXIT_SUCCESS;}


0 0
原创粉丝点击