"读取xml文件"

时间:2014-08-25 19:17:52

标签: c++ mfc msxml

我正在加载并读取xml文件。我在使用Visual Studio 6时取得了成功,但现在我已经改为Visual Studio 10并且没有编译。

我正在使用MFC类开发SDI应用程序。

这是错误:

  1. 错误1120 - ,一个未解析的外部
  2. 未处理的例外
  3. 代码:

    CComPtr<IXMLDOMElement> iRootElm;
        ::CoInitialize(NULL);
        HRESULT hr = m_plDomDocument.CreateInstance(__uuidof(DOMDocument));
        if (FAILED(hr))
        {
            _com_error er(hr);
            AfxMessageBox(er.ErrorMessage());
            //EndDialog(1);
        }
    
    
    
        CString strFileName ("TestCase.xml");
    
        // convert xml file name string to something COM can handle (BSTR)
        //fname = strFileName;
        _bstr_t bstrFileName;
        VARIANT_BOOL *flag = NULL;
    
        bstrFileName = fname.AllocSysString();
    
        _variant_t source;
        source.vt = VT_BSTR;
        source.bstrVal = bstrFileName;
        //VARIANT source = (VARIANT)fname;
    
    
        // call the IXMLDOMDocumentPtr's load function to load the XML document
    
        variant_t vResult;
        //vResult = ;
        vResult = m_plDomDocument->load(source , flag);
        bool v = (bool)vResult;
    
        if ((bool)vResult == true) // success!
        {
            // now that the document is loaded, we need to initialize the root pointer
            //m_pDocRoot = m_plDomDocument->createElement((_bstr_t)"TestCase" , temp); // ->documentElement;
    
            m_pDocRoot = m_plDomDocument->get_documentElement(&iRootElm);
            //m_pDocRoot = m_plDomDocument->createElement((_bstr_t)"TestCase.cml" );
            AfxMessageBox(_T("Document loaded successfully!"));
            //AfxMessageBox(m_plDomDocument);
        }
    
        else
        {
            AfxMessageBox(_T("Document FAILED to load!"));  
        }
    }
    

1 个答案:

答案 0 :(得分:0)

根据Visual studio帮助

  

致命错误C1120

     

此错误表示需要重新安装Visual C ++。

:(