2 Replies Latest reply on Mar 20, 2017 7:43 AM by philippep2776167

    Get Attribute Value from Structured Book

    philippep2776167

      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?

        • 1. Re: Get Attribute Value from Structured Book
          4everJang Level 3

          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[i].name == sAttName ) {

                         bFound = true;

                         if( oaAttrs[i].values.length > 0 ) {

                              sRetVal = oaAttrs[i].values[0];

                         }

                    }

                    i++;

               }

               return sRetVal;

          }

           

          Good luck

           

          4everJang

          • 2. Re: Get Attribute Value from Structured Book
            philippep2776167 Level 1

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