当前位置: 首页 > 工具软件 > RapidXml > 使用案例 >

用rapidxml来读取xml文件

左康安
2023-12-01

下载rapidxml的库

 

http://rapidxml.sourceforge.net/

 

 

我们这里使用

#include "rapidxml_utils.hpp"

就可以搞定我们的基本需求

 

using namespace rapidxml;

 

 

file<WCHAR> f("document.xml");

xml_document<WCHAR> doc;    // character type defaults to char

doc.parse<0>(f.data());    // 0 means default parse flags

xml_node<WCHAR> *node1 = doc.first_node();//document
xml_node<WCHAR> *nodeB= node1->first_node();//body


//p
for(xml_node<WCHAR> *nodeP = nodeB->first_node(L"w:p"); nodeP; nodeP = nodeP->next_sibling(L"w:p") )
{
        //r
        for(xml_node<WCHAR> *nodeR = nodeP->first_node(L"w:r"); nodeR; nodeR = nodeR->next_sibling(L"w:r"))
        {
            for(xml_node<WCHAR> *nodeT = nodeR->first_node(L"w:t"); nodeT; nodeT = nodeT->next_sibling(L"w:t"))
            {

                WCHAR *VAL = nodeT->value();
                CString str(nodeT->value());

                //这里就是我们要找的节点value
            }//T
           
        }//R

    }//P

 类似资料: