|
-
July 19th, 2002, 11:45 AM
#1
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
-
July 22nd, 2002, 12:50 AM
#2
-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.
-
July 22nd, 2002, 03:25 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|