Click to See Complete Forum and Search --> : problem with loadXML("my_xml_string")


getzel
July 19th, 2002, 11:45 AM
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



;) ;)

dkar
July 22nd, 2002, 12:50 AM
-1 do mean that your document is incorrect.
After getting -1 exam yourDoc->parseError object.



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

mao_03
July 22nd, 2002, 03:25 AM
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.


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;