CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: XML with C++

  1. #1
    Join Date
    Sep 2001
    Posts
    169

    XML with C++

    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


  2. #2
    Join Date
    Sep 2001
    Posts
    169

    Re: XML with C++

    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.


  3. #3
    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    17
    Howdy,

    You could try the Xerces XML code from the Apache Project, I think the URL is:

    xml.apache.org
    ==========================
    Sid Young
    Sunny Queensland
    Australia (Oz)

  4. #4
    Join Date
    May 1999
    Posts
    44
    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

  5. #5
    Join Date
    Sep 2001
    Posts
    169

    Unhappy

    Originally posted by sidy
    Howdy,

    You could try the Xerces XML code from the Apache Project, I think the URL is:

    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

  6. #6
    Join Date
    Sep 2001
    Posts
    169

    Unhappy

    Originally posted by sidy
    Howdy,

    You could try the Xerces XML code from the Apache Project, I think the URL is:

    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

  7. #7
    Join Date
    Apr 2001
    Location
    Brisbane, Australia
    Posts
    17
    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.
    ==========================
    Sid Young
    Sunny Queensland
    Australia (Oz)

  8. #8
    Join Date
    May 1999
    Location
    Switzerland
    Posts
    58

    Post your code again

    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

  9. #9
    Join Date
    Sep 2001
    Posts
    169

    Re: Post your code again

    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

  10. #10
    Join Date
    May 1999
    Location
    Switzerland
    Posts
    58
    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

  11. #11
    Join Date
    Sep 2001
    Posts
    169
    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

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