11 Replies Latest reply on Sep 29, 2016 2:56 PM by beverly

    Strategies for DOM manipulation

    jcrumbs

      I'm doing this to alter the DOM of third party webapps in a webviewer for my users:

       

      Storing the DOM to a field with GetLayoutAttributeObject(), manipulating that string with Text Functions (such as adding values to input field tags, hiding elements... the type of stuff you might use JS DOM functions or jQuery for), and putting that into a new viewer.

       

      It works but it's the type of cumbersome that a plugin (such as the way BE_JSONPath operates on strings containing a JSON object) could easily make so easy. It also seems like the type of thing there would totally be a plugin for. Does anyone know of one? Or a different strategy that is less cumbersome.

        • 1. Re: Strategies for DOM manipulation
          beverly

          there are custom functions for parsing XML, as well as for JSON parsing.

           

          can you provide a small sample of what you are working on and/or some of your methods you are using now?

           

          many people might also do this kind of work through the web directly and post back in more digestible formats to FileMaker to consume.

           

          beverly

          • 2. Re: Strategies for DOM manipulation
            Johan Hedman

            Here is a good XML parse Custom Function that I use often

            FileMaker Custom Function:ExtractData ( XML ; Attribute ; Instance )

             

            Here is a good example file how to parse JSON

            How to Parse JSON (or any other language) in FileMaker - Soliant Consulting

            1 of 1 people found this helpful
            • 3. Re: Strategies for DOM manipulation
              beverly
              1 of 1 people found this helpful
              • 4. Re: Strategies for DOM manipulation
                nicolai

                if you must do it this way, Beverly and Johan suggested good links.

                 

                I would add XLST for XML parsing to the mix.

                 

                I can only add, that I do not think FileMaker is the best tool to manipulate DOM (sorry, FMI). There is one tool specifically designed for this - JavaScript. On top of this there are quite a few frameworks, like jQuery, to make it even easier. Any compelling reason to use FIleMaker (apart from being a FileMaker developer)? Obviously, I don't quite understand what are you doing and if you can explain a bit more it would make more sense.

                 

                Nicolai

                1 of 1 people found this helpful
                • 5. Re: Strategies for DOM manipulation
                  fmpdude

                  Just to add to Nicolai's list, in Java, there is also "JDOM", which is INCREDIBLY intuitive and easy to use. I've been using it for years and years.

                   

                  Of course, that's not "in FM", but you could access a JDOM program from INSERT FROM URL.

                   

                  HOPE THIS HELPS.

                  • 6. Re: Strategies for DOM manipulation
                    jcrumbs

                    Hi Beverly,

                     

                    Grrr... my cumbersome version works but has brought me to a new and totally unrelated intractable heartache. My Let() statements just stop working at some point and can not be added to without throwing errors that make no sense, forcing me to delete them and rewrite them in a new variable assignment, making a cumbersome thing that was actually getting easy when you get used to it waaay more cumbersome. To show you that, and to answer your question at the same time, here is a screen shot. You can see how I've been doing this and it has been working perfectly up until this line, and then just it says it is expecting a "(" while highlighting the very same "(". I don't know what to do about that. I've now got 4 variable assignments with Let() statements in them instead of one long elegant one because of this. Periodically making a new one the same thing will start happening. It will just throw a random nonsense error and then I have to delete and start again.

                     

                    Let()s aside, this has been working. I should mention that I've been able to use this strategy also to add values to forms, add an 'onload' attribute, as well as a <script> and actually submit the form from the web viewer without user interaction. That webviewer I hide. Then I just show the user themselves logged in in a different webviewer. So that is the mission accomplished. But these crazy erroneous errors are now making my life strange and hard  

                     

                    (Oh and lastly I needn't even use replacer2 instead of replacer, since I can reassign that variable I believe, it's just that was the last troubleshoot I tried before taking the screenshot. Hopefully someone can help!)

                     

                    Screen Shot 2016-09-29 at 10.21.16 AM.png

                    • 7. Re: Strategies for DOM manipulation
                      jcrumbs

                      Oh whoops I added a comment instead of a reply (new to the forum). Here's my response:

                       

                      Hi Beverly,

                       

                      Grrr... my cumbersome version works but has brought me to a new and totally unrelated intractable heartache. My Let() statements just stop working at some point and can not be added to without throwing errors that make no sense, forcing me to delete them and rewrite them in a new variable assignment, making a cumbersome thing that was actually getting easy when you get used to it waaay more cumbersome. To show you that, and to answer your question at the same time, here is a screen shot. You can see how I've been doing this and it has been working perfectly up until this line, and then just it says it is expecting a "(" while highlighting the very same "(". I don't know what to do about that. I've now got 4 variable assignments with Let() statements in them instead of one long elegant one because of this. Periodically making a new one the same thing will start happening. It will just throw a random nonsense error and then I have to delete and start again.

                       

                      Let()s aside, this has been working. I should mention that I've been able to use this strategy also to add values to forms, add an 'onload' attribute, as well as a <script> and actually submit the form from the web viewer without user interaction. That webviewer I hide. Then I just show the user themselves logged in in a different webviewer. So that is the mission accomplished. But these crazy erroneous errors are now making my life strange and hard

                       

                      (Oh and lastly I needn't even use replacer2 instead of replacer, since I can reassign that variable I believe, it's just that was the last troubleshoot I tried before taking the screenshot. Hopefully someone can help!)

                       

                      Screen Shot 2016-09-29 at 10.21.16 AM.png

                      one more too:

                      • 8. Re: Strategies for DOM manipulation
                        jcrumbs

                        Screen Shot 2016-09-29 at 10.34.12 AM.png

                        this will now happen anywhere, of its own will, even in fresh variable assignments. I can't figure out the patter of why it will fail like this periodically, I'd say more often than not.

                        • 9. Re: Strategies for DOM manipulation
                          jcrumbs

                          Last example, this is how I got a script in there. (I also had to add that ID). It works but I'm at my wits end with this weird error in Let() statement issue.

                           

                          Screen Shot 2016-09-29 at 10.51.28 AM.png

                          • 10. Re: Strategies for DOM manipulation
                            jcrumbs

                            Hi Nicolai,

                             

                            FileMaker is the design constraint. My project is a FileMaker integration so I've got to use it. I'm actually using JS (see my responses to Beverly) but I'm using Replace to get those scripts into the DOM. I'm not sure how else I can get this all hooked up. Basically the plan is to hide the webviewer off somewhere, copy the DOM, add all the things I need (values to form fields, onload script to body, script to head to fire on load) and then use that to login and show the user another webviewer all logged in. It's working nicer than I expected but my Let() statements have gone haywire (also in my responses to Beverly) so I'm onto a worse heartache I feel.

                             

                            Open to all advice.

                             

                            Thanks!

                            • 11. Re: Strategies for DOM manipulation
                              beverly

                              no worries, jc!

                              If you can copy the text in your Let(), we may be able to assist.

                               

                              I know I make many mistakes with Let() if I don't break it out something like this:

                               

                              Let(

                              [ firstassignment

                               

                              ; secondassignment

                               

                              ; result = Case

                                   ( a = 1 ; do this

                                   ; a = 2 ; do that

                                   ; "" )

                               

                              ]; result // what get's returned

                              )