Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine why a call to IXMLDOMDocument::load() fails?

Tags:

c++

xml

com

I am trying to debug what appears to be an XML parsing issue in my code. I have isolated it down to the following code snippet:

HRESULT
CXmlDocument::Load(IStream* Stream)
{
    CComVariant xmlSource(static_cast<IUnknown*>(Stream));
    VARIANT_BOOL isSuccessful;
  * HRESULT hr = m_pXmlDoc->load(xmlSource, &isSuccessful);
    return (hr == S_FALSE) ? E_FAIL : hr;
}

Note: m_pXmlDoc is of the type CComPtr<IXMLDOMDocument>.

It appears that the call to IXMLDOMDocument::load() (marked with the *) is failing - IOW, it is returning S_FALSE.

I am not able to step into load() to determine why it is failing, as it is a COM call.

The MSDN page for this method doesn't seem to be giving a lot of insight.

I have a few hunches:

  • The XML is not well-formed
  • The XML file is too large (approximately 120MB)
  • It is a memory-related issue (the process size gets to > 2GB at the time of failure)
    • NB: A registry key has been set to allow the process size to be this large, as the largest valid process size for WinXP, AFAIK, is 2GB).

Any ideas as to why this call could be failing?

like image 344
LeopardSkinPillBoxHat Avatar asked Jan 27 '10 02:01

LeopardSkinPillBoxHat


1 Answers

The following code will fetch the specific parser error from the DOM and it's location in the source XML.

CComPtr<IXMLDOMParseError> pError;
CComBSTR sReason, sSource;
long nLine = 0, nColumn = 0;

m_pXmlDoc->get_parseError(&pError);
if(pError)
{
    pError->get_reason(&sReason);
    pError->get_srcText(&sSource);
    pError->get_line(&nLine);
    pError->get_linepos(&nColumn);
}

sReason will be filled with the error message. sSource will contain the errorneous source line in the XML. nLine and nColumn should get set to the line number and column of the error, although in practice these two aren't always set reliably (iirc, this is especially true of validation errors, rather than parser/well-formedness ones).

like image 127
Phil Booth Avatar answered Sep 29 '22 00:09

Phil Booth