CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2006
    Posts
    3

    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

  2. #2
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    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.
    Last edited by Siddhartha; April 1st, 2006 at 08:23 AM.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Apr 2006
    Posts
    3

    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

  5. #5
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    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?

  6. #6
    Join Date
    Feb 2006
    Location
    iran
    Posts
    15

    Re: Reading Xml File in VC++


  7. #7
    Join Date
    Nov 2001
    Posts
    17

    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...

  8. #8
    Join Date
    Oct 1999
    Location
    Missouri, USA
    Posts
    453

    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
    If you need an answer, don't forget to try this link:
    http://www.codeguru.com/forum/search.php?
    __________________

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured