tags:

views:

193

answers:

2

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?

+2  A: 

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).

Phil Booth
Thanks for the suggestion - I have extracted the error, and it appears to be different every time I run it. This suggests to me that I am running into memory issues, not malformed XML. I have opened up a new question about this:http://stackoverflow.com/questions/2152492/maximum-process-sizes-on-32bit-vs-64bit-windows-versions
LeopardSkinPillBoxHat
A: 

If the XML file is opened by another Task or Proccess the Load() method can't load the file but it doesn't state that the loading has failed. I consider this behaviour as a bug.

So you have to check the Property documentElement - if it is null, load() has failed, too.

shmia