Skip to main content
Inspiring
January 24, 2020
Answered

Can I validate an FM document using ExtendScript?

  • January 24, 2020
  • 3 replies
  • 759 views

Hi,

 

I am looking to check if a book/doc is valid (same as doing Esc v d) but programatically.

 

I can't find this in the documentation; the closest I can find is:

CallClient("FmValidateXml", "XML pathname");

 

Is there an equivilent of this for binary FM docs and books?

 

Also, is there any documentation available for built-in API clients beyond the few examples in the FDK docs?

 

Thanks,

Dan

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer Russ Ward

Hi Dan,

 

I've done this one time, element-by-element like Rick suggests. It was just a simple "valid or not" check. I found this in my code:

 

if(F_ApiGetInt(docId, elemId, FP_ValidationFlags) != 229376)
   invalidStructure = True;

 

I can't remember how I came up with that integer. FP_ValidationFlags is a bitwise value, and besides that, I would think that "valid" would equal 0. But it works. I might have just run it through the debugger to see what decimal value popped up with a valid element. I don't remember and I failed to leave any comments to myself in the code.

 

This may or may not help.

Russ

 

3 replies

4everJang
Legend
September 1, 2021

Easier and probably faster than checking element by element is using FM's built-in validation checking code. Here is a script that checks the document and scrolls to the first invalid element in the document, when one is found.

 

function ValidateDocument( oDoc )
{
	var oRoot = oDoc.MainFlowInDoc.HighestLevelElement;
	if( oRoot.ElementDef.Name == 'NoName' )
	{
		return false;
	}

	var oInvalid = oRoot.NextInvalidElement;

	if( oInvalid.ObjectValid( ) )
	{
		oDoc.IsOnScreen = true;
		oDoc.TextSelection = oInvalid.TextRange;
		oDoc.ScrollToText( oInvalid.TextRange );
		return false;
	}
}

if ( ValidateDocument( app.ActiveDoc ) )
{
	alert( 'Document is valid' );
}
else
{
	alert( 'Document is not valid' );
}
Russ WardCorrect answer
Legend
January 27, 2020

Hi Dan,

 

I've done this one time, element-by-element like Rick suggests. It was just a simple "valid or not" check. I found this in my code:

 

if(F_ApiGetInt(docId, elemId, FP_ValidationFlags) != 229376)
   invalidStructure = True;

 

I can't remember how I came up with that integer. FP_ValidationFlags is a bitwise value, and besides that, I would think that "valid" would equal 0. But it works. I might have just run it through the debugger to see what decimal value popped up with a valid element. I don't remember and I failed to leave any comments to myself in the code.

 

This may or may not help.

Russ

 

frameexpert
Community Expert
Community Expert
January 24, 2020

Hi Dan, I don't have time to test something, but I think this element property will be helpful: ContentIsStrictlyValid. I suspect that you can traverse the element tree and test this property for each element. At least that would be the place to start. -Rick

www.frameexpert.com