14 Replies Latest reply: Jun 5, 2007 3:18 AM by HowardTreisman RSS

    Parsing XML with Adobe Javascript

      I am using the standard SQL QPAC to fetch list data from a database. As we already know, the standard SQL APAC cannot retrieve multiple rows, but I use the "FOR XML AUTO" in my SQL statement so that all rows are returned in XML format.

      I now only need to parse the XML and put the items into my drop-down list.

      Does anyone have script samples that can parse XML from within LiveCycle? You would think that the capability exists since the product is based on xml/xfa.

      Thanks,
      Duncan Campbell
      Xcellerate IT
        • 1. Re: Parsing XML with Adobe Javascript
          Community Member
          Are you looking to parse it in a script qpac? If so then you can store the XML in an xml process variable, then use getProcessDataValue() from PATExecutionContext to retrieve a Document object for the DOM.

          Chris
          Adobe Enterprise Developer Support
          • 2. Re: Parsing XML with Adobe Javascript
            Community Member
            Chris,

            Can you please point me towards the proper documentation of this stuff: getProcessDataValue() and PATExecutionContext?

            I searched high and low for anything on them, and found nothing.

            Thanks,
            Duncan
            • 3. Re: Parsing XML with Adobe Javascript
              Community Member
              Sure, take a look at the JavaDocs that come with the LiveCycle Workflow SDK. Under Documentation/api/LiveCycle_Workflow_SDK_API_Reference.

              FYI, in a script QPAC the PATExecutionContext is an implicit object accessed under patExecContext. In a custom QPAC it is a parameter to the execute method.

              Chris
              Adobe Enterprise Developer Support
              • 4. Re: Parsing XML with Adobe Javascript
                Community Member
                Chris,

                I tried putting the following XML into an xml variable, but I received an error instead:

                12Otis3

                Do you know precisely how to perhaps get the proper XML results from a SELECT statement that will go into an XML variable?  I used
                "SELECT CLIENT_NAME as item from clients as list ORDER BY CLIENT_NAME FOR XML auto, elements" and I'm using a standard SQL QPAC to return the XML results.

                Once I get the XML properly into the XML variable, I will try to use the getProcessDataValue() method.

                Duncan Campbell
                • 5. Re: Parsing XML with Adobe Javascript
                  HowardTreisman CommunityMVP
                  Hi Duncan

                  If you have problems doing it that way, you can also download our SQLPlus QPAC, which will allow you to iterate over a result set and format the output in a number of ways, including a simple comma separated list. You can then use a simple script in the form to unpack the list into a dropdown.

                  Regards,
                  Howard
                  http://www.avoka.com
                  • 6. Re: Parsing XML with Adobe Javascript
                    Duncan,

                    It may be just as simple to write a QPAC that does the query and returns a comma-delimited list as a string. You could then have the form take that string as a hidden field and parse it into the drop-down list in the same method that Workflow provides the submission choice drop-down list.

                    Clifton
                    • 7. Re: Parsing XML with Adobe Javascript
                      Community Member
                      heh, Howard typed faster. :)
                      • 8. Re: Parsing XML with Adobe Javascript
                        Community Member
                        Wow guys,

                        You all provided very good solutions that I may try someday. I really mean that, but my intention with this particular workflow is to use only the tools I get out of the box. I really want to know the base components well so that I get a full understanding of what the provided QPACs can and cannot do.

                        That way I get to learn about how to use some of the loosly documented methods like getProcessDataValue(). Forgive my ignorance, can anyone please tell me how I am to script a call to this method, if you have used it already?

                        Thanks heaps,
                        Duncan Campbell
                        • 9. Re: Parsing XML with Adobe Javascript
                          Community Member
                          You're getting an error because that XML is not well formed so a DOM cannot be built for it.  There needs to be a root node, something like enclosing all that in ....

                          I'm attaching a simple workflow I exported.  It sets the value of an XML variable, and then using a script QPAC to call getProcessDataValue() and retrieve a Document object that can be used to parse the XML.

                          Chris
                          Adobe Enterprise Developer Support
                          • 10. Re: Parsing XML with Adobe Javascript
                            Duncan,

                            Did you ever have any luck with this? Any additional pointers?

                            I think I am going to do something similar. I am planning on sending in an email that contains XML data of just 9 fields (collected from a form online - outside of the LC system and then using the Email Receiver to collect the email. The email body is the XML data). So, I need to parse this out and set the elements to variables to populate my PDF form.

                            If I get something working, I will try to post back.

                            Thanks,
                            Jennifer
                            • 11. Re: Parsing XML with Adobe Javascript
                              HowardTreisman CommunityMVP
                              Hi Jennifer
                              You may be able to get a fair bit of it done just using the SetValue QPAC. I think (although I'm not sure) that you can use expressions like:
                              /process_data/myxml/rootnode/row[2]/firstname

                              So as long as you know the number of rows you want to process, you may be able to get by.

                              Let us know how you get on.

                              howard
                              • 12. Re: Parsing XML with Adobe Javascript
                                Community Member
                                Hello,

                                Actually, I ended up doing something a little different.

                                Since I only have 9 fields to get parse, I did use the Set Value QPAC, but I used substring-after and substring-before functions. I had to do this in two different Set Value QPACS, I couldn't group them together for some reason. So, the body of the email contains my XML data and I set the body to a variables and then parse it out in those 2 Set Value QPACS.

                                It works great!

                                -Jennifer
                                • 13. Re: Parsing XML with Adobe Javascript
                                  I could not able to retrieve the remote xml file(which means from server to another server) in Mozilla Firefox and some times inn IE also.
                                  I found the Error: "Error: uncaught exception: Permission denied to call method XMLDocument.load"

                                  please help me in this area if you find or knew.

                                  Thank you
                                  • 14. Re: Parsing XML with Adobe Javascript
                                    HowardTreisman CommunityMVP
                                    Hi Thiru
                                    It's a little difficult to work out what you're doing from your posting.
                                    I suspect it may be that you're trying to load a document in Reader. This is not allowed, you must use Acrobat. (Or reader enable the form.)
                                    Howard
                                    http://www.avoka.com