Some more digging showed the solution, although I do feel there should be an easier way:
The highest level element of the main flow may show a red plus in the Structure View but this is not reflected in any of its validity properties. I would have expected the ContentIsStrictlyValid property to be False if any of the descendants is invalid, but that does not seem to be the case. The property only looks at the element's own children and the invalidity is not propagated to the top. Still, FM does show a red plus in the Structure View if any descendant element is invalid. It would have been so nice to see this reflected in the ContentIsStrictlyValid property. I do believe that descendants are part of the content, too.
I have now written a small recursive piece of code to determine whether all elements in the flow are valid.
function ValidateDoc ( oDoc )
{
var oRoot = oDoc.MainFlowInDoc.HighestLevelElement;
if ( !oRoot.ObjectValid( ) || !oRoot.ContentIsStrictlyValid || oRoot.InvalidHighestLevel )
return false;
return ValidateChildren( oRoot );
}
function ValidateChildren ( oParent )
{
var oChild = oParent.FirstChildElement;
while ( oChild.ObjectValid( ) )
{
if ( !oChild.ContentIsStrictlyValid || !ValidateChildren( oChild ) )
return false;
oChild = oChild.NextSiblingElement;
}
return true;
}