These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Importing Multiple XML files into a Single Form

ChuckLew
Registered: Apr 16 2010
Posts: 12

I have a form that is used by several different departments. Once its been filled out, I need to be able to send one copy of the form -- with all the data in one document -- on to a supervisor. I can export and import just fine, but that only allows me to overwrite the data in the form with the new imported data. How can I add data from one of the exported XML files to the existing data in the form? That way, I could export each copy to XML and then add them to each other, one at a time (all at once would be great too, of course).

I have manually opened then XML file that get exported and cut and pasted the instances out of each file into a single file, and have been able to import that successfully. What I need to now is how I can do this from within the form (say with buttons). I know I can create a form button to allow exporting to XML, and another one for importing too. From what I gather form some other post I've seen on this, I need to figure out a way to store the data in the existing form > import the new XML data > and then add the original data back. Unfortunately, that is where I start getting confused.

Could someone help me through the coding of this, or am I completely off track here? Specifically, how to I store the data so that its still available after I import the new XML data (and in what format)? Also, how do I reinsert the original data without overwriting the newly imported data? Is it safe to assume that these functions should be part of an "import" button on the form?

In case it helps, here are some specifics on my form. I have multiple instances of:

form1.ShipAVAILs.AvailBinder.AvailInstance.ShipSpacer
on each copy of the form. Inside of ShipSpacer, the are sever other fields with a bunch of data. In addition I may or may not have multiple instances of:

form1.CMAVs.CMAVBinder.CMAVInstance.ShipSpacer
in each form, with a similar set of sub fields inside. There are a few other fields, but none that I absolutely need to export/import (the data remains the same for all the submitters).

Thanks in advance for any help you can lend me on this issue.

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, it appears that you have a LiveCycle form? Is this correct?

You can control which fields import and export data. But the solution depends entirely on the kind of form you have. This would be much easier to do with an AcroForm. LiveCycle requires more work.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ChuckLew
Registered: Apr 16 2010
Posts: 12
Thomp, thanks for the quick response!

I am using LiveCycle. I'm not familiar with AcroForm, and am under some IT constraints so it may not be an option for me. As far as which types of fields I have inside of the "ShipSpacer" wrapper; I have 7 dropdowns, 3 date fields, 1 radio button (yes & no), and 7 text fields (two of which, the user of the form may add additional instances of as needed -- using a set of buttons for each field).Here is a look at the XML of one of the "ShipSpacer" blocks. I've edited some of the field names to show the difference in names inside the "AvailInstance" and "CMAVInstance" wrappers.

<ShipSpacer><ShipBoarder><BackgroundBoxWhite></BackgroundBoxWhite><BackgroundBoxRed>hidden</BackgroundBoxRed><BackgroundBoxYellow>hidden</BackgroundBoxYellow><BackgroundBoxGreen>hidden</BackgroundBoxGreen><AvailDataType or CMAVDataType depending on which area of the form/><HullNameAndNumber/><AvailStartDate or CMAVStartDate depending on which area of the form/><AvailEndDate or CMAVEndDate depending on which area of the form/><PercentAvailExpended/><PercentPhysicaProgress/><AvailStatus or CMAVStatus depending on which area of the form/><AvailType or CMAVType depending on which area of the form/><ContractType/><NSA/><Prime/><Location/><LastMilestone/><OnTime/><NextMilestone/><MilestoneDate/><ShipAVAILSummary or ShipCMAVSummarys depending on which area of the form><SumHeader xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/><availSummaryRow or cmavSummaryRow depending on which area of the form><availSummary orcmavSummary depending on which area of the form/><addButton xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/><removeButton xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/></availSummary or cmavSummaryRow depending on which area of the form><Spacer xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/><ConcernsHeader xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/><majConcernsRow><majorConcerns/><addButton xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/><removeButton xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/></majConcernsRow><footerRow xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup"/></ShipAVAILSummary or ShipCMAVSummarys></ShipBoarder></ShipSpacer>

There are also 4 different colored "Background Boxes" that simply hide or show based on the status of AvailStatus or CMAVStatus. I am decently familiar with JavaScript, but not the particulars of how to apply it to PDF forms.

I willing to tackle the difficulties, but I'm not sure if I know what I'm up against. Does any of this info help you point me in the right direction?
ChuckLew
Registered: Apr 16 2010
Posts: 12
I'm leaning toward using some combination of these methods:

• saveXML()
• loadXML()
• exportAsXFDF()
• importAnFDF()
• exportXFAData()
• importXFAData()
• append()
• addInstance(true)

but I can't quite figure out of to weave them together. Am I completely off track?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It's pretty easy to export partail data out of an XFA form by deleteing nodes out of the datamodel before export.

But I haven't figured out how to do a partial import. Modifying the field binding does not seem to do anything. The only think I can think of at this point is to save the data model and recreate the bits you want to perserver after importing.

There maybe a better methodology. Take a look at this blog:
http://forms.stefcameron.com/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ChuckLew
Registered: Apr 16 2010
Posts: 12
Thanks again, for your help on my issue. I'm looking through the source you gave me for possible answers.

Although I am really looking to store and import partial piece of the form's data, I'm not really concerned with the rest of the form's data (at least in this particular case). So, if I can store and merge the forms data in its entirety easier than just the pieces I need, that will work for me (overwriting the other parts of the form won't effect the results I'm after).

I'd also consider using the "Merge Data Files Into Spreadsheet" feature, but I need to figure out how to get the data back in the form from the Excel file. I've even been researching how to parse multiple XML file using external methods (like VBS script), and export a single file for import into the PDF form.

If it were only myself I was concerned about using this method I would be fine with cutting and pasting from the individual export files into one XML file. Unfortunately, I need something that other users can consistently do on their own. Which means, I need something that can merge this data with a series of button clicks (as opposed to requiring anyone to analyze/edit code in anyway). I'm open to any solutions that are out there. What do other users do in this sort of situation?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The data handling features built-into Acrobat are pretty simple and straight forward. So anytime you get fancy with the data you have to write some custom code for handling it. Solutions vary from JS on the form to server side processing. But I think you have the right idea about using a VB program to munge up the data the way you want it to be.

However you also might want to look at the LiveCycle Data connection (the SourceSet model) and see if that will help. If the Excel file is exposed through ODBC the form can connect to it directly.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The import and export fucntions will only work in Reader if the PDF file has Special Import/Export Rights Enabling. These rights can only be applied through the LiveCycle ES Rights server. So, for all practical purposes, importing and exporting XML with Reader is not an option.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ChuckLew
Registered: Apr 16 2010
Posts: 12
I've been kicking this can down the road for a bit now, and I think I'm ready to dig back in. The idea I had about going with a VBS script doesn't fly with the document owners, because I need it to be usable to people who may be uncomfortable working with an external script file (don't ask...that's still a sore subject for me, but that concept is off the table). I thought I had it all figured out, and was going to:

• get XML data and store as a variable;
• create dataobject and store all form XML data in dataobject;
• import external/additional data into main form;
• get new AvailInstance.ShipSpacer data (if any) and store as a variable;
• get new CMAVInstance.ShipSpacer data (if any) and store as a variable;
• append dataobject within the AvailInstance node;
• append dataobject within the CMAVInstance node;
• import XML from dataobject;
• delete dataobject;

Similar to some of the things you wrote about in this post: [url]http://www.acrobatusers.com/forums/aucbb/viewtopic.php?pid=40212[/url] and specifically used in this demo file: [url]http://www.windjack.com/PDFSamples/XMLDataObjDemo.pdf[/url]

I worked out how to store the XML the way I wanted, and found some of the basic JS commands I thought I would need to implement everything. It was only after I began to look deeper into this, that I realized what you were getting at in your first comment to this post:

thomp wrote:
This would be much easier to do with an AcroForm. LiveCycle requires more work.
It seams that LiveCycle does not have the same functionality when it comes to handling attachments. Most obvious, is that I can not create and attachment. However, I am able to add one to the document permanently, before distributing the form. So now my thought is to bind an attachment to the LiveCycle attachment and then follow some logic along these lines:

• get XML data and store as a variable;
• access the attached file and store all form XML data in dataobject;
• import external/additional data into main form;
• get new AvailInstance.ShipSpacer data (if any) and store as a variable;
• get new CMAVInstance.ShipSpacer data (if any) and store as a variable;
• append the XML in the attached file within the AvailInstance node;
• append the XML in the attached file within the CMAVInstance node;
• import XML in the attached file;
• delete XML in the attached file;

So I just wanted to check back in with you, and see if this is a sound way to attack my problem. If you have any pointers on how to achieve this using LiveCycle JavaScript, please share. Oh and if I'm headed for another brick wall please let me know.

I have learned more than I though I would about the inner workings of PDF forms. Although I have not (yet) accomplished my goal, this has been a rewarding experience.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This is a bit much for a forum post. But I can tell you that most of the operations you're interested in, importing data, attaching files, and modifying attachments, are privileged operations. For all practical purposes they can only be accomplished in the full Acrobat from a folder level trusted function.

You can make a PDF a privileged context by saving it as certified. Then for any user with the digital signature that was used to certify the document it will be privileged. But this is thin. It's very easy to break certification by modifying the document. To perform these operations in Acrobat you'll need to have a folder level script on the users system.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script