记得前些天,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;
}
}