|
-
April 1st, 2006, 08:05 AM
#1
Reading Xml File in VC++
Hi,
I want to read a xml file through vc++ . plz post any referrence or sample code if u have . i am new in .net coding so plz provide the steps how to do it .
what i need is that i have a xml file and my c++ code should read the file and show the contents in output.
Thanks
-
April 1st, 2006, 08:20 AM
#2
Re: Reading Xml File in VC++
 Originally Posted by swaraj
I want to read a xml file through vc++ . plz post any referrence or sample code if u have . i am new in .net coding so plz provide the steps how to do it .
.NET? Are you coding using C++ or C++.NET?
You can load an XML DOM using MSXML interfaces.
In general -
Once you load the document using IXmlDomDocument::Load you will get the root XML Node (IXmlDomNode) that you can use to walk the tree.
Last edited by Siddhartha; April 1st, 2006 at 08:23 AM.
-
April 1st, 2006, 08:25 AM
#3
Re: Reading Xml File in VC++
Are you interested in a managed or unmanaged application?
For the former, see the System::XML namespace. For the later see MSXML.
-
April 1st, 2006, 08:35 AM
#4
Re: Reading Xml File in VC++
I am using VS .NET 2005 (vc++).I am very novice to VC++ .NET. I need a xml file to open through vc++ and want to dispaly the contents into my active document.I am not getting the DOM Reference exactly.Plz give some sample code to read the xml file and print the output on the active document.
Thanks
-
April 1st, 2006, 08:37 AM
#5
Re: Reading Xml File in VC++
Actually, it takes time to understand the DOM reference... Given those leads above, it should be easy for you to search samples.
Did you try?
-
April 2nd, 2006, 07:12 AM
#6
Re: Reading Xml File in VC++
-
May 18th, 2006, 05:36 AM
#7
Re: Reading Xml File in VC++
I hope this helps:
includes:
Code:
#include <msxml2.h>
#include <comdef.h>
#import <msxml4.dll>
using namespace MSXML2;
string buffer;
char buffer1[80];
int XML_CargarFichero(CString szPath, CComPtr<MSXML2::IXMLDOMDocument> &iXMLDoc)
or
int XML_CargarFichero(CString szPath, MSXML2::IXMLDOMDocument2Ptr &iXMLDoc)
{
VARIANT_BOOL bSuccess=false;
iXMLDoc.CoCreateInstance( __uuidof(MSXML2::DOMDocument40));
iXMLDoc->async = false;
try
{
iXMLDoc->validateOnParse = true;
printf ("Cargando fichero %s",(char *)(LPCSTR)szPath);
if ((bSuccess=iXMLDoc->load((char*)(LPCSTR)szPath))== VARIANT_FALSE)
{
MSXML2::IXMLDOMParseErrorPtr perror;
perror=iXMLDoc->parseError;
printf ("Error al cargar fichero %s\n",(char *)(LPCSTR)szPath);
printf (" %s \n",(char *)perror->reason);
printf("Linea %ld Columna %ld\n",
perror->line, perror->linepos );
bSuccess=false;
}
}
catch(_com_error &e)
{
sprintf(buffer1,"%08x - %S\n", e.Error(),
e.Description() );
buffer.assign(buffer1);
bSuccess=false;
AfxMessageBox(e.Description());
}
return bSuccess;
}
the call to the function:
CComPtr<MSXML2::IXMLDOMDocument> iXMLDoc;
CString szXML;
szXML="C:\\parametrosconDTD.xml";
bool bret=XML_CargarFichero(szXML,iXMLDoc);
Jaa ne.
Last edited by Siddhartha; May 18th, 2006 at 05:48 AM.
Reason: Added Code-Tags...
-
May 19th, 2006, 02:49 PM
#8
Re: Reading Xml File in VC++
This link gives an example of how to use a wrapper class. The sample project is dialog based, but it might be helpful.
http://www.codeproject.com/cpp/C___XML_wrapper.asp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|