Solved

How to load an XML file

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ADO Memory leak with DELPHI 2007 37 155
Complete beginner needs help making a cron job 9 104
has77  challenge 9 67
MaxSpan challenge 9 65
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

18 Experts available now in Live!

Get 1:1 Help Now