开发者

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

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 i开发者_运维问答s 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜