bool CMarkup::IsWellFormed() const;

You may need to determine if the CMarkup object contains a well-formed XML document at a later point than the call to SetDoc such as in a situation where the object has been passed to a function in your program and you don't know if it contains a well-formed XML document. Simply call IsWellFormed which returns true if the CMarkup object contains a well-formed document. Here is an example of an ill-formed document:

CMarkup xml( "<msg>Hello" ); // no end tag!
bool bWell = xml.IsWellFormed(); // false

With CMarkup, a "well-formed" document is one which has been successfully parsed with a single root element and all child elements contained properly. This method indicates whether the document appears to be a well-formed XML document although it is not a guarantee of XML compliance.

See also Containment Hierarchy.

 

comment posted Question about xml file check

stefano 17-Jan-2008

I've one file that contains a '&' character in an element value. This file should be recognized as corrupted but the function CMarkup::IsWellFormed() is not able to detect this error. Does CMarkup have a function that is able to check the element values? I'm sure that this file is corrupted because MS Explorer detected it as corrupted.

You're right, it is not a properly composed XML document because of the unencoded ampersand in the element data but CMarkup does not check encoding correctness. As described above, the IsWellFormed method does not scan the document, it only reports true if all the child elements are contained properly and there is a single root element. This relaxed well-formedness is determined during the parse of the Load or SetDoc method. The single root element requirement is maintained for backwards compatibility even though CMarkup can be used perfectly well with multiple root elements (see Log Files Without A Root Element).

CMarkup is designed for quick processing to extract and modify information in documents rather than any kind of strict encoding check. In fact the role of strictness for the sake of rejecting entire documents is often counter-productive as discussed in The Problem With DTD and XML Schema Validation, since what is more important is verifying that the data extracted is safe and acceptable from the logic where the data is utilized. There is currently no function to verify that element data is encoded properly. But you can test documents using the Alt+F7 MSXML Validate function in the free firstobject XML Editor.