Get Attribute Value from Structured Book

Explorer ,
Mar 20, 2017

Copy link to clipboard

Copied

Hello,

In a Structured book, i need to get on attribute valus (on the highest element) but ...

In a FM document, i can get value from an element by looping through all my document by "wraping" the element text and get the attributes (using : element.TextRange.beg/end).

But in a structured book, i can't wrap the "element text" because it's not text, so how can i get the value of my highest element?

TOPICS
Scripting

Views

286

Likes

Translate

Translate

Report

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

1 Correct Answer

Advocate , Mar 20, 2017
4everJang Advocate , Mar 20, 2017
Not sure what you mean by 'looping through all my document' and 'wraping the element text'. Attributes are normally not visible in the text content of a structured document. To get to the attributes, you select the element and search its attribute list for the values. You can also do this on the book, as that has structured content which works basically in the same way. The only real difference is that the book does not have flows, so you get to the highest level element in a different way:In a ...

Likes

Translate

Translate
Jump to answer Jump to answer
Advocate ,
Mar 20, 2017

Copy link to clipboard

Copied

Not sure what you mean by 'looping through all my document' and 'wraping the element text'. Attributes are normally not visible in the text content of a structured document. To get to the attributes, you select the element and search its attribute list for the values. You can also do this on the book, as that has structured content which works basically in the same way. The only real difference is that the book does not have flows, so you get to the highest level element in a different way:

In a structured FM document:

var oDoc = app.ActiveDoc;

var oRoot = oDoc.MainFlowInDoc,HighestLevelElement;

In a structured FM book:

var oDoc = app.ActiveBook;

var oRoot = oDoc.HighestLevelElement;

To get the attribute value for an attribute you can use this function:

function GetAttribute( oElement, sAttName ) {

     var oaAttrs = oElement.Attributes;

     var sRetVal = "";

     var i = 0;

     var bFound = false;

     while( !bFound && i < oaAttrs.length ) {

          if( oaAttrs.name == sAttName ) {

               bFound = true;

               if( oaAttrs.values.length > 0 ) {

                    sRetVal = oaAttrs.values[0];

               }

          }

          i++;

     }

     return sRetVal;

}

Good luck

4everJang

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
philippep2776167 AUTHOR LATEST
Explorer ,
Mar 20, 2017

Copy link to clipboard

Copied

Thanks a lot for your code.

I was stuck with the attribute and making a "while function" correctly. With a clear code like your it's 10.000 times easier to understand. (I think I had my noze too long time in my code and couldn't find what was wrong).

Likes

Translate

Translate

Report

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