Expand my Community achievements bar.

LoadXML Method

Avatar

Former Community Member
Has anyone used this method succesfully? I cannot seem to get it working.

I have reader enabled my pdf with reader extensions and have certified it as well.



here is the code.



xfa.data.loadXML("/C/Data/importData v2.1.xml", false, true);



Is there anyone that can help me?
20 Replies

Avatar

Former Community Member
As far as I know loadXML method is a generic Node method which allows you to load XML as a string. For example loading XHTML into rich text field values, etc.



I have never tried to load data using this xfa.data.loadXML. I normally use xfa.host.importData(filename) to load data from an external source. The PDF must be reader enabled for this as well.

Avatar

Former Community Member
Thank you! I was having a similar problem with loadXML and had almost resorted to parsing the XML file and setting each field value separately.



The only reason I had been focusing on loadXML to import data was because I thought there may have been some symmetry with saveXML method.

Avatar

Former Community Member
It is not that you cannot use the loadXML method. It will take XML in XDP format for the data object model as a string. The docs are vague on what the first parameter is, but I dont think it can load from an external source.



If you look at the saveXML you can see the format which loadXML will take.

Avatar

Former Community Member
THIS IS THE DOCUMENTATION

====================

param1 : A valid string representing the name of the XML document.



param2 (Optional) : A boolean value indicating if the root node within the XML document should be ignored.



True (default) : Ignores the root node of the XML document, and appends the remaining XML nodes

directly to the current XML Form Object Model object.



False: Appends the root node of the XML document directly to the current XML Form Object Model object.



param3 (Optional) : A boolean value indicating if the data from the XML document should overwrite the

information for the current XML Form Object Model object.



True: Replaces the content of the current XML Form Object Model object with the XML document data.



False : Appends the XML document data to the current XML Form Object Model object.



THIS IS THE CODE

====================

xfa.data.loadXML("/C/Data/importData v2.1.xml", false, true);



THIS IS THE ERROR

====================

GeneralError: Operation failed.

XFAObject.loadXML:1:click undefined:Exec

Xml parsing error: not well-formed (invalid token) (error code 4), line 1, column 1 of file



MY OPINION

=====================

The documentation is not vague its either incorrect which yet again shows that Adobe's documentation is not in sync with their products.

This is not the first time that the documentation has been found misleading.



Adobe Should have a serious re-valuation regarding the correctness of their documentation.



CONCLUSION

========================

I would like a developer from Adobe to comment on this post to get the real purpose of LoadXML.



Thanks for all your reply's

Avatar

Level 3

The documentation for this method is abysmal.  I added comment on one of the versions but it was deleted.  The string argument is the actual XML, not a file name, and the "Reference_Node" is any XML node (data or form, though I only use the data DOM and can't vouch for form DOM).

Avatar

Former Community Member
Andre,<br /><br />I assume what you are trying to achieve is to be able to create a form (using Designer 7) that references to a XML data file and being able to access to the elements and values of the XML document.<br />Here is one way to do it:<br /><br />- Assuming your XML data file has the following structure and being named as mydata.xml and its location is C:\mydata.xml<br /><br /><?xml version="1.0" encoding="UTF-8"?> <br /><purchase><br /> <product><br /> <price>399.00</price><br /> <name>camara</name><br /> </product><br /> <product><br /> <price>49.95</price><br /> <name>case</name><br /> </product><br /> <product><br /> <price>199.00</price><br /> <name>palm</name><br /> </product><br /></purchase><br /><br />- Let's say one of your task is to display the product name in the dropdownlist.<br /><br />- Launch your Designer 7 and open a new form. If the form wizard appears, just close it.<br /><br />- On the new form, drag a new "Dropdown list" object from the "standard library" onto the form.<br /><br />- Here is the javascript for the "Dropdown list" on the "form:ready" event<br /><br />var objDataGroup = xfa.resolveNode("$data.purchase");<br />var lenght = objDataGroup.nodes.length;<br /><br />for (var i=0; i < lenght; i++) <br />{<br /> this.addItem(objDataGroup.nodes.item(i).nodes.item(1).value); <br />}<br /><br />- Make sure it is set for "Javascript" and run at "client".<br /><br />- Go to File>Form Properties> and select Defaults tab<br />- in the Preview section, select "interactive form" for the preview type and locate your data file (it is "C:\mydata.xml" in this case) then click on OK.<br /><br />- The next step is to test your form by selecting your "PDF preview" tab in Designer 7.<br /><br />Good luck.

Avatar

Former Community Member
Hi there thanks for you reply.



I have tried this approach as well but this only works while you using the designer and not intended for production.



Can you or anyone confirm this?

Avatar

Former Community Member
That is correct; using File>Form Properties>Defaults is only a means of testing your form from a form design perspective. I haven't used the aforementioned loadXML method from within Designer. I have only used Form Server to load an XML data file into a form.

Avatar

Former Community Member
Andre,



When you click the preview button in Designer - there is a mini - version of Form Server in the Designer which is changing your XDP into a PDF on the fly. It also takes the data file specified in the form properties and merges that data onto your form.



When you save out the PDF fromt he designer and render it in Acrobat then you are bypassing the data merge step. Note that your data bindings are still there. You can accomplish the data population by opening the data file either by menu(Advanced>Forms>Import Data to Form) or programatically.



Or you can have the PDF generated on the fly by Form Server and pass in the data file that you want merged.

Avatar

Former Community Member
Thanks for all the suggestions, but we are trying to use the adobe forms abit different.



We want our main application x to generate an xml file and save it to disk. Then we want the adobe pdf form to access the xml file. The main problem is that the user can selectively choose which data he/she wants to import and disgard certain parts.



yet again thanks for helping me!

All your post is making me understand how other companies use the adobe forms.

Avatar

Former Community Member
What you could try and do is use a single invisible field to load the XML. From your application generate your XML, encoded (using URL Encoding) and wrap it inside another XML document, which is XFA this time. Then use the importData, which will allow the use to select the XML and upload the data into the invisible field (and decodes it at the same time).



Once you have the data as a string you could use either the XML object in Acrobat javascript or loadXML method in XFA script.



The only problem is that importData blows away all other fields, so if it is loading fragments you are looking for, then you need to do a saveXML before you start importData



I have not tried this so I dont know if there any other issues involved in something like this. By the way the XML object in Acrobat does not allow access to the file system either.

Avatar

Former Community Member
Thanks for this information. I will look into it, It seems as if it can create some problems in the long run but thanks for your view.



All suggestions are really appreciated and valued as it helps me look at the problem from a different angle.

Avatar

Former Community Member
David,



Do you have any code sample on how to use LoadXML to share with us? Thanks.

Avatar

Former Community Member
As I mentioned in a previous reply, loadXML method is a member of the Node class. Basically this means every object within the hierarchy be it form object, value object, or data object, etc will inherit the Node class. Everything is based on a Tree/Node relationship in the XFA object model.



You can identify the methods which are inherited in the Designer by the function assist popup. If the method/property is in italic, then it is inherited from the base class and may or may not be applicable to the object.



LoadXML expects a XFA-based XML string to be passed to it and reloads the XML for the Node. There is no one single use for LoadXML, but we will probably end up using it quite alot.



The only sample I do have is setting the value of a rich text field via script. Since Rich Text Values are in XHTML format (basic use of fonts, spans, b, i, etc), you need to load it using loadXML. rawValue & formattedValue only return the text/set the text and not the XHTML. Note: I have not seen any other way to do this yet - There might be a simpler method!



For example:

var sXHTML = "<body xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\" xfa:APIVersion=\"Acroform:2.2.4333.0\" xfa:spec=\"2.1\"><p style=\"margin-top:0pt;margin-bottom:0pt;font-family:'Myriad Pro';font-size:10pt;font-weight:normal;font-style:normal\">Test Field</p></body>";

TextField1.value.exData.loadXML(sXHTML);



This example modifies a value node, but you could supply data for a data node, for example xfa.data.loadXML(XML). The XML in this case would have to be a XFA-based representaion of the XML.



Additionally, you can look at saveXML to see what the XML for the node actually is.



Hope I haven't confused anybody

Avatar

Former Community Member
the documentation is wrong.

the first parameter is not a name of an xml document. first parameter is a valid XML.



you can look in ADOBE Javascript Scripting Reference by applyXPath. with some changes you can use this example for loadXML. i tried it out and it works.



is it possible to set a parameter for a pdf with the location for an external XML document?



i am searching for a way to set the parameter for importData dynamic.



thanks

Avatar

Former Community Member
Hi!



Could you please show us how you make those modifications due to applyXPath. That example (in the Adobe Java Script reference) works just fine in Acrobat Javascript debugger, but I can't make it work in designer.



best regards,

Håkon

Avatar

Former Community Member
Yep that worked.



Great stuff. Do you know how to apply the same code in order to populate a text field and a list box.



Regards

Andy

Avatar

Former Community Member
Dave (O'Hanlon)



How exactly do you use the xfa.host.importData method. I have tried this:



xfa.host.importData("C:\$user\PatientDetails.xml");



and all I get in return is:



GeneralError: Operation failed.

Global.importXFAData:-1:ready undefined:Exec

Avatar

Former Community Member
This is great stuff and useful to a lot of folks (not just me ;^) -- can someone post a working example?



TIA,

John