使用msxml遍历重复的node问题

本文介绍使用MSXML解析特定格式XML文件的方法。通过示例展示了如何遍历XML节点并获取所需信息。解决了编译过程中的错误,并提供了一个实用的遍历函数。

记得前些天,wang同学说过这个问题,因为一直用的是apache的xml解析库,ms的一直没用过,今天刚好看了下,折腾了半天,终于找到正解了。

假设结点为

<xml>
<media>
<name ID="43">。。。</name>
<tjcode>
<acode>
<code istrue="0">1</code>
<code istrue="0">2</code>
<code istrue="0">3</code>

</acode>

</xml>

 

我用的是 http://www.codeproject.com/KB/cpp/msxmlcpp.aspx#Requirements 此处经过封装的类

 

这个类如果你编译demo时不能通过,请修改此行

 

原来是

template<class T>
class AFX_EXT_CLASS CInterfaceCallingWrapper

 

修改为

 

template<class T>
class  CInterfaceCallingWrapper

 

否则编译会出现

1>d:/msxmlcpp_demo/source/interfacewrapper.h(274) : error C2491: 'CInterfaceCallingWrapper<T>::CInterfaceCallingWrapper' : definition of dllimport function not allowed
1>d:/msxmlcpp_demo/source/interfacewrapper.h(281) : error C2491: 'CInterfaceCallingWrapper<T>::CInterfaceCallingWrapper' : definition of dllimport function not allowed

等等错误

 

遍历方法

 

void PrintNodes(CXMLDOMDocument2& Doc)
{
    CXMLDOMNodeList List(Doc.SelectNodes(_T("//xml/media")));
    for (int ii = 0; ii < List.GetLength(); ii++)
    {
        CXMLDOMNode Node(List.GetItem(ii));
        cout<<Node.SelectSingleNode(_T("name")).GetText()<<endl;
        CXMLDOMNodeList List2;
        List2 = Node.SelectNodes(_T("tjcode/acode/code"));
        for (int jj = 0; jj < List2.GetLength(); jj++)
        {
            CXMLDOMNode Node2(List2.GetItem(jj));
            cout<<Node2.GetText()<< " ";
        }
        cout<<endl;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值