Solved

How to load an XML file

Posted on 2002-07-05
5
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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