Skip to main content
4everJang
Legend
April 16, 2014
Question

How can I find out if a structured doc is valid?

  • April 16, 2014
  • 1 reply
  • 878 views

Hi all,

I need to establish the validity of a Doc before my script transforms it to XML and applies an XSLT in the process. I have searched the FM12 scripting guide but cannot find any Doc property or method to figure out whether or not the Doc is valid. Am I looking in the wrong place?

Kind regards

Jang

This topic has been closed for replies.

1 reply

4everJang
4everJangAuthor
Legend
April 16, 2014

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;

}

Legend
April 16, 2014

Hi Jang,

This is the only way I've found do to it; that is, step through the entire tree and look at elements individually. It may just be that the granular nature of the API expects us to write routines like this ourselves, if we want there to be an easier way (at least after the first time!).

Russ

4everJang
4everJangAuthor
Legend
April 16, 2014

Hi Russ,

What strikes me is that apparently the FM code already contains this routine - as visible in the Structure View - but it was not deemed important enough to share with scripters via an additional property. Whereas there are 100s of properties that do not seem so useful to most of us. Strange policy.

Ciao

Jang