Solved

How to load an XML file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 56
Doc'in system (example?) BA 7 87
centeredAverage challenge 8 130
zeroMAx challenge 20 87
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. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now