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