Skip to main content
Inspiring
March 20, 2017
Answered

Get Attribute Value from Structured Book

  • March 20, 2017
  • 1 reply
  • 604 views

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?

This topic has been closed for replies.
Correct answer 4everJang

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

1 reply

4everJang
4everJangCorrect answer
Legend
March 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 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

Inspiring
March 20, 2017

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).