• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can I validate an FM document using ExtendScript?

Explorer ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

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

TOPICS
Scripting , Structured

Views

555

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jan 27, 2020 Jan 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

...

Votes

Translate

Translate
Community Expert ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 27, 2020 Jan 27, 2020

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 01, 2021 Sep 01, 2021

Copy link to clipboard

Copied

LATEST

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' );
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines