Solved

How to load an XML file

Posted on 2002-07-05
5
462 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 98
Complete beginner needs help making a cron job 9 118
mapAB Challlenge 35 146
x-bar in Google Sheets 2 55
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

832 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