When CMarkup Load Returns false

In CMarkup, when the Load method returns false, it is either because it could not load the file, or the data was not well-formed XML. If GetDoc() returns a non-empty string then the file was loaded but the parser encountered an error.

Processing GetResult

Update March 24, 2009: The GetResult method in CMarkup release 11.0 (not CMarkupMSXML though) returns a structured markup result which allows you to determine exactly what happened. After Load, GetError can return something like "UTF-8 length 38 lone end tag 'C' at offset 10" from which you cannot programmatically determine what went wrong, but GetResult returns markup which can be processed:

<read encoding="UTF-8" length="38"/><lone_end_tag tagname="C" offset="10"/>

CMarkup xml;
bool bLoadResult = xml.Load( strFilename );
bool bLoadedNonEmpty = false;
CMarkup mResult( xml.GetResult() );
if ( mResult.FindElem(MCD_T("read")) )
  if ( MCD_STRTOINT(mResult.GetAttrib(MCD_T("length"))) )
    bLoadedNonEmpty = true;
  while ( mResult.FindElem() )
    // Handle specific return codes
    MCD_STR strRC = mResult.GetTagName();
    if ( strRC == MCD_T("lone_end_tag") )

CMarkupMSXML load

If you are using the MSXML Wrapper CMarkupMSXML, it wraps the MSXML load method which I think uses a streamed I/O approach (not necessarily loading the entire file into memory before parsing it), and building an internal node tree to represent the document. Unlike in the CMarkup class, when the CMarkupMSXML Load fails, the GetDoc method will always return an empty string even if the file access was successful.

See also: