MSXML2::IXMLDOMDocument2Ptr pXMLDocument;  
   HRESULT hr_ConInitialize;
hr_ConInitialize = CoInitialize(NULL);
if(FAILED(hr_ConInitialize))
{
  return 0;
}    HRESULT hr= pXMLDocument.CreateInstance(__uuidof(MSXML2::DOMDocument40));  
if (!SUCCEEDED(hr))
{
return 0;
}
    pXMLDocument->load("news_100701_9.mpf");  
    MSXML2::IXMLDOMElementPtr pRootNode = pXMLDocument->documentElement;  
 
    MSXML2::IXMLDOMNodeListPtr pPersonNodes = pRootNode->selectNodes("Attachments");  
    CString s;  
    long size = pPersonNodes->length;  
    for (i = 0; i<size; i++)  
    {  
        MSXML2::IXMLDOMNodePtr pPersonNode = pPersonNodes->item[i]; 
 s.Format("%s",(LPCTSTR)pPersonNode->text);
 MessageBox(NULL,s,"XML",MB_OK);
    }  从网上找的相似代码该的,还是报异常。
我的
。。下面是XML中的内容,我想获取其中的C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg  <Attachments>
    <Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_1.jpg"/>
    <Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_2.jpg"/>
    <Attachment RelPath="C:\Documents and Settings\Administrator\桌面\素材\0913R1.files\images\0913R1_c_3.jpg"/>
    <Attachment RelPath="images\thumb_01.jpg"/>
    <Attachment RelPath="contents.txt"/>
  </Attachments>
问题是报的异常在红色部分那里

解决方案 »

  1.   

    报的异常时在
    MSXML2::IXMLDOMNodeListPtr pPersonNodes = pRootNode->selectNodes("Attachments"); 
     
      

  2.   

    首先用IE打开XML文件看能不能正确解析,确认XML文件没有问题
      

  3.   

    其中news_100701_9.mpf为XML文件的别名
      

  4.   


    那就帮你顶一下等高手帮你解决了,没用过你这个XML解析类,为了代码能在Windows和Linux用,我一般用的是tinyxml
      

  5.   

    你确定你加载成功了,那个文件news_100701_9.mpf你加上绝对路径试试
      

  6.   

     看下pXMLDocument->load("news_100701_9.mpf");  返回什么,或者在后面加个 
      int err =getlasterror();看下
      

  7.   

    对这个不熟悉。
    我习惯用CMark类解析xml文件。很方便的。
      

  8.   

    报什么错误?用GetLastError()看看返回值是多少
      

  9.   

    MSXML2::IXMLDOMElementPtr pRootNode = pXMLDocument->documentElement;  
    // PRootNode即Attachments
        CString s;  
        long size = pRootNode ->length;  
        for (i = 0; i<size; i++)  
        {  
            MSXML2::IXMLDOMNodePtr pPersonNode = pRootNode ->item[i]; 
             s.Format("%s",(LPCTSTR)pPersonNode->text);
             MessageBox(NULL,s,"XML",MB_OK);
        }  
      

  10.   

    windows和linux一般不是用tinyxml吧,我见的多的是mxml,这是个C的,
      

  11.   

    在加载的时候Load(“.xml”)这一步就非法访问了。。
      

  12.   

    pXMLDocument->load("news_100701_9.mpf"); 估计后缀的原因吧。干嘛用这个类。
    这个类费做爱的劲,享受作孽的滋味。去看一下 c类  超级好用。
    费作孽的劲,享受做爱的感受。
      

  13.   


    昨天晚上刚接触tinyxml,看这很强大,没有在程序中实战过。。