Solved

How to load an XML file

Posted on 2002-07-05
5
463 Views
Last Modified: 2013-11-20
I need to open an xml file, read the contents and store the column data in arrays. Display the data in a grid. Make changes to the data and save as a new xml file.

How do i load a xml file in VC++ ?

Thank you
0
Comment
Question by:l_angelo
5 Comments
 
LVL 12

Accepted Solution

by:
migel earned 50 total points
ID: 7131797
Hi!
the MS way is to yse MSXML component for working with XML
for example:

     IXMLDOMDocument2Ptr spXMLDom;
     HRESULT hr = CreateObject(L"Msxml2.DOMDocument.3", IID_IXMLDOMDocument2, (void**)&spXMLDom);
     if (FAILED(hr))
          {
return hr;
          }
     VARIANT_BOOL bRes = spXMLDom->load(_variant_t(strName.c_str()));
     if (bRes == VARIANT_TRUE)
                   {
// work here with XML
                   }
     return S_OK;
0
 
LVL 3

Expert Comment

by:jlsjls
ID: 7131932
Take a look at following link :
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q246230

Hope it helps.
jlsjls.
0
 

Expert Comment

by:zhoujohnson
ID: 7133227
BOOL CXMLFile::LoadFile(const CString &strPathName, IXMLDOMDocument **doc)
{
        IXMLDOMDocument* document = NULL;
     IXMLDOMParseError* parseError = NULL;
     //IXMLDOMElement* element = NULL;    
     HRESULT hr;
     BSTR bstr = NULL;
     VARIANT_BOOL varOkay;
     hr = CoInitialize(NULL);
     if (FAILED(hr)) {
          return FALSE;
     }

     hr = CoCreateInstance(CLSID_DOMDocument, NULL,
     CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
     IID_IXMLDOMDocument, (LPVOID*)&document);
     if (!document) {
          return FALSE;
     }

     document->put_async(VARIANT_FALSE);
     bstr = strPathName.AllocSysString();
     document->load (_variant_t(bstr),&varOkay);
     SysFreeString(bstr);
     
     if (varOkay) {
         
     } else {
          long line, linePos;
          BSTR reason = NULL;
         
          document->get_parseError(&parseError);
          parseError->get_errorCode(&hr);
          parseError->get_line(&line);
          parseError->get_linepos(&linePos);
          parseError->get_reason(&reason);
         
          CString strMsg;
          strMsg.Format(_T("Error 0x%.8X on line %d, position %d\r\nReason: %s"),
               hr, line, linePos, CString(reason));
          MessageBox(NULL,strMsg, _T("Error Loading XML"), MB_ICONWARNING);
          parseError->Release ();
          document->Release ();          
          SysFreeString(reason);
          return FALSE;
     }

     
     if ( *doc)
          (*doc)->Release();
     *doc = document;
     

     return TRUE;

}
0
 
LVL 11

Expert Comment

by:griessh
ID: 7378779
Dear I_angelo

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "migel"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7420214
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question