Re: Reading Xml File in VC++
Quote:
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.
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.
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
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? ;)
Re: Reading Xml File in VC++
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.
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