Click to See Complete Forum and Search --> : XML with C++
anushreeg
May 15th, 2002, 06:41 AM
has anybody worked in XML with C++
i have written following code and i don't know why it's not working
#include "stdafx.h"
#include "stdio.h"
#include "atlbase.h"
#import "msxml3.dll"
using namespace MSXML2;
inline void EVAL_HR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
int main(int argc, char* argv[])
{
USES_CONVERSION;
try
{
IXMLDOMDocumentPtr objDOMDoc;
EVAL_HR(CoInitialize(NULL));
EVAL_HR(objDOMDoc.CreateInstance("Msxml2.DOMDocument.3.0"));
_variant_t varXml("C:\\Sample.xml");
_variant_t varOut((bool)TRUE);
objDOMDoc->async = false;
varOut = objDOMDoc->load(varXml);
IXMLDOMNode *NewNode;
NewNode = objDOMDoc->createElement("Location");
objDOMDoc->documentElement->appendChild(NewKid);
and this statement appendchild gives me exception
following is my XML file
<?xmlversion ='1.0' encoding='utf-8'?>
<Sample>
<child>"remove this node"</child>
</Sample>
please help me.
it's urgent.
anu
anushreeg
May 15th, 2002, 08:52 AM
i think all these will work with msxml4.dll i have this dll but i couldn't register it
it gives me error
Load Library failed-a dll initialization routine failed.
sidy
May 16th, 2002, 08:43 PM
Howdy,
You could try the Xerces XML code from the Apache Project, I think the URL is:
xml.apache.org (http://xml.apache.org/)
Robert Bielik
May 17th, 2002, 01:12 AM
I second the Xerces XML package at xml.apache.org . The code gets MUCH cleaner than using the M$ COM XML approach. And it works too... ;)
/Rob
anushreeg
May 20th, 2002, 11:11 PM
Originally posted by sidy
Howdy,
You could try the Xerces XML code from the Apache Project, I think the URL is:
xml.apache.org (http://xml.apache.org/)
WHAT ARE THE FILES WHICH ARE NEEDED TO START WITH IT FOR MSXML I DOWNLOADED ALL THE DLLS OF XMLDOM PARSER BUT I COULDN'T FIND ANY DLLS ON THIS SITE,COULD YOU PLEASE SENE ME ANY LINK.
ONE MORE THING I WANT THAT IT IS A VALIDATING PARSER I KNOW THAT SOME PROPERTY CAN BE SET OR SOME METHOD CAN BE CALLED TO MAKE THE PARSER VALIDATING BUT IT DOESN'T WORK,CAN YOU TELL ME WHY?
ANU:(
anushreeg
May 20th, 2002, 11:12 PM
Originally posted by sidy
Howdy,
You could try the Xerces XML code from the Apache Project, I think the URL is:
xml.apache.org (http://xml.apache.org/)
WHAT ARE THE FILES WHICH ARE NEEDED TO START WITH IT FOR MSXML I DOWNLOADED ALL THE DLLS OF XMLDOM PARSER BUT I COULDN'T FIND ANY DLLS ON THIS SITE,COULD YOU PLEASE SENE ME ANY LINK.
ONE MORE THING I WANT THAT IT IS A VALIDATING PARSER I KNOW THAT SOME PROPERTY CAN BE SET OR SOME METHOD CAN BE CALLED TO MAKE THE PARSER VALIDATING BUT IT DOESN'T WORK,CAN YOU TELL ME WHY?
ANU:(
sidy
May 20th, 2002, 11:28 PM
Howdy,
If you go to the apache site and select the C++ link, I assume you are using C++ then download the binaries for your distribution and un zip them into a directory.
Then add the path to the DLL's to your system path env. variable and in VC++ add the include and lib directories to your project.
And, yes it does validation if you need it. Best bet is subscribe to the mailing list and look at the samples.
Don't bother getting the source distribution, you only want the binary dist. to get going straight away.
Daniel Frey
May 21st, 2002, 03:26 AM
Hi,
it's hard to read your code, because you pasted it as HTML, but Codeguru doesn't interpret it. So if you post your code again or attach the project as ZIP, I may help you. Additionally I have written a class for MFC, which wrapps the XML-COM class, so you can work with CStrings instead of variant etc. Maybe you can use it. But it's still in development.
Dan
anushreeg
May 21st, 2002, 04:45 AM
Originally posted by Daniel Frey
Hi,
it's hard to read your code, because you pasted it as HTML, but Codeguru doesn't interpret it. So if you post your code again or attach the project as ZIP, I may help you. Additionally I have written a class for MFC, which wrapps the XML-COM class, so you can work with CStrings instead of variant etc. Maybe you can use it. But it's still in development.
Dan
now my earlier problem is solved but the new problem i'm facing is validation i know MSXML perser allows validation i tried to use one of it's properties ValidateonPrse and also tried to use Validate method of IXMLDOMDocument2 interface but none of them is validating my XML i don't know how i can make them work do you have any idea.
Anu
Daniel Frey
May 21st, 2002, 05:18 AM
I usually validate my XML's by loading the document to parse via xmldoc->load(path). Then you check for errors with
xmldoc->get_parseError(errorObject). You get errorstring, line, character pos, etc.
Please let me know if it worked!
Dan
anushreeg
May 21st, 2002, 06:15 AM
Originally posted by Daniel Frey
I usually validate my XML's by loading the document to parse via xmldoc->load(path). Then you check for errors with
xmldoc->get_parseError(errorObject). You get errorstring, line, character pos, etc.
Please let me know if it worked!
Dan
no that may work but i want the error right at the time i insert try to insert something in my DOM tree else i would get the error only when i restart my application and load the file and my purpose can only be solved by validate function which is not working please help me
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.