CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Location
    New Jersey
    Posts
    17

    Question problem with loadXML("my_xml_string")

    hi to all.
    I'm loading an xml string into an IXMLDOMDocument via loadXML.
    Why does it return to me the # -1.I'm assuming it means that it didn't load properly.

    However ,I did it in a try/catch and it doesn't throw any _com_error exceptions,so obviously something else must be wrong.

    Everything else involved in setting up the DOMDocument works.

    Also when trying to get the root document I use the following code:

    m_pDocRoot = pXMLDoc->documentElement;
    pXMLDoc->get_documentElement(&m_pDocRoot);

    if the DOMDocument would load correctly would that code be sufficient or does it need more??

    Thanks
    Getzel




  2. #2
    Join Date
    Aug 2001
    Location
    Russia, Moscow
    Posts
    26
    -1 do mean that your document is incorrect.
    After getting -1 exam yourDoc->parseError object.


    Code:
    
    if (yourDoc->loadXML( yourStr )==-1){
    // You can use this for error message
      yourDoc->parseError.reason;
      yourDoc->parseError.errorCode;
      yourDoc->parseError.linepos;
      yourDoc->parseError.line;
      yourDoc->parseError.srcText;
      ...
    }
    
    Denis.

  3. #3
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    224
    To load a XML document from a XML formatted string i made the following function.
    To get the root node i used the queryInterface since getNode did not return the root node but simply nothing.

    Code:
    	IXMLDOMDocument* pXmlDocTemp	= NULL;
      IXMLDOMNode*     pXmlNodeTemp = NULL;
    	BSTR bstrXmlString;
    	HRESULT hr = 0;
    
        // Create an empty XML document
    	// ******************************************************************************		
      hr = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
                            IID_IXMLDOMDocument, (void**)&pXmlDocTemp);
    	if (hr == S_OK) {
    		VARIANT_BOOL varIsOk;
        
    		bstrXmlString = XMLHelperFunctions::asciiToBSTR(l_sParamRef.c_str());
    
    		// Loading XML String into the XML Document
    		// ******************************************************************************				
    		hr = pXmlDocTemp->loadXML(bstrXmlString, &varIsOk);
    		if ( hr == S_OK) {
    		
    			// so get a pointer to the IXMLDOMNode interface 
    			// ******************************************************************************		
    			hr =  pXmlDocTemp->QueryInterface(IID_IXMLDOMNode,(void**)&pXmlNodeTemp);
    			if ( hr != S_OK) 
          {
    				safeRelease(&pXmlDocTemp);
    				safeRelease(&pXmlNodeTemp);
    			}
    		}
    		else {
    			safeRelease(&pXmlDocTemp);
    		}
    	}
    	else {
    		safeRelease(&pXmlDocTemp);
    	}
    	::SysFreeString(bstrXmlString);
    	bstrXmlString = NULL;
    CU

    Ingo

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