Expand my Community achievements bar.

Retrieve data from XML file

Avatar

Former Community Member
How can I import a XML file into pdf doc and how can I retrieve its data as string, in order to populate a drop down List, without using XML Schema Data Connection.



Thank you for your time!
Add topics

Topics help categorize Community content and increase your ability to discover relevant content.

17 Replies

Avatar

Former Community Member
>>>How can I import a XML file into pdf doc



In this example, take a look at the javascript on import button. It will show you how to import the xml data into the form.




jimmypham, "Phone bill examples" #, 29 Mar 2005 3:05 pm



>>>>how can I retrieve its data as string, in order to populate a drop down List, without using XML Schema Data Connection.



Can you clarify more on this question about what do you want to do?

Avatar

Former Community Member
First of all, I would like to thank you for your answer, but unfortunately I didn't mean that. What I am looking for is a way to retrieve the data as a string from an xml file that is saved in a specified directory in my hard drive. Is there any function that could do that?



Thank you in advance!

Avatar

Former Community Member
First of all you cannot load an XML file in Designer without Reader Extensions, either using xfa.host.importData or any or the import methods in AcroForm javascript. Also, since the XML objects where not available in 6, you cannot parse an XML file in anything other than version 7 of Reader/Acrobat.



So, if you do have Reader 7 (Reader-Enabled) or Acrobat 7, you could use the Attachment object to load the XML file and in turn use the XML object to parse and extract the XML data.



For example, placing the following code on a button will prompt the user to select an XML data file and manually parse it for data.



if (app.viewerVersion >= 7)

{

event.target.importDataObject("XMLData");

var oData = event.target.getDataObjectContents("XMLData");

var sData = util.stringFromStream(oData);

var oXML = XMLData.parse(sData, true);

event.target.removeDataObject("XMLData");



// Populate Fields

TextField3.rawValue = oXML.MyField1.value;

TextField4.rawValue = oXML.MyField3.value;

TextField1.rawValue = oXML.MyField2.value;

}

else {

app.alert("Acrobat 7.0 or later is required");

}



My external XML file is:



<?xml version="1.0" encoding="UTF-8"?>

<MyProperties>

<MyField1>A</MyField1>

<MyField2>B</MyField2>

<MyField3>C</MyField3>

</MyProperties>



Once the data is parsed, you can access it through the same hierarchy as Designer. It actually generates an XFAObject to represent each data node within the XML Document.



The other thing to note is that you cannot load data automatically from an init or calc event. You MUST have some user interaction (i.e. on the click event of a button)

Avatar

Former Community Member
David,

I'm trying to use the above sample to solve a little issue (I've got to allow for the importing of data from two different sources at different times in the doc life cycle -each is based on the same schema but on import the second xml file will override the other when I'm only interested in a few data points on the second one...)

Anyway, bringing the second bit of data in as an xml file and being able to parse only the pieces I need seems to be a great solution -if I can get it to work.

I've got a modified version of the above script on a button on my form. It seems to work fine up to the point where it prompts me for the file to import. Then nothing else happens.

I'm not sure if there are considerations I'm missing in dealing with more complex schema (and one not necessarily created in the best possible way for working with Designer) or if I've somehow mucked up something else important. Unfortunately I'm pretty much stuck with the schema as-is since it's the standard to which my client and their partners all are building to.

Any more info you can give on importing/parseing xml data selectively would be GREATLY appreciated!

Jennifer

Avatar

Former Community Member
Can you send me the form and sample data file you are working with to "dohanlon@yahoo.com" and I will have a look. Are you using Acrobat or Reader? If it is Reader, you will need Reader Extensions.

Avatar

Former Community Member
David,

I am using Acro Pro 7.0.2 and anticipate that the end users will be using the same (know all about the issues with Reader Extensions).

I'll send my form/data on shortly -thanks in advance for taking a peek. I know just enough of jscript and xml to muck things up without a little backup!



Jennifer

Avatar

Former Community Member
Basically the problem lies in the data you are trying to import. The XMLData object within Acrobat is very specific in the type of declaration it requires to enable it to parse the XML correctly. My previous example was a little to simplistic in terms of XML being loaded (did not have attributes, etc). The code is fine, I have not changed anything at all except to get the correct path to the data.



What you need to use id the xfa namespace declaration around the data packet you are trying to import. For example:



<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">

... your data starting with <PRIA ...

</xfa:data>



Then on the form side you can access it using

parent.parent.RecordingEndorsement.sfRecordingEndorsementData.RecordedCounty.rawValue = oXML.PRIA_DOCUMENT.<node>



Follow the same structure as in the XML at this point. Attributes are also access the same way as child nodes.



Just to note, and I think I mentioned this before, you cannot do this in automated fashion (i.e. when the form loads or some script which does not involve user input) since this would break the security model. The user must select the XML file to import.

Avatar

Former Community Member
David,

I just finally had a chance to sit down and actually dig a bit into what you sent back.

Can you tell me why the namespace info doesn't automatically show up when you do an export data call from a designer form?

(The file EndorsementFeeder_Data.xml was generated as an export from a Designer form I created to help myself out for testing)

Do I need to make/hide a field for the namespace? Seems a little strange to need to do that if the data is tied to the referenced data source.

I appreciate your help!

Jennifer

Avatar

Former Community Member
Hi David,



I am setting an xml file as Data File in the Forms Properties and then at run time, I am looping through the elements to populate drop down. It works fine in Designer, however when I deploy the form onto the Form server, its not loading that xml.



Is there any other way to get an xml at run time and loop through it without using Data Connection?



Thanx in advance.

Praveen

Avatar

Former Community Member
Are you passing in the XML data as the data parameter for the renderForm () call in LC Forms (Form Server)?



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Hi Chris,<br />Thanx for the reply, please see below the code i wrote to read the xml and populate a drop down. This works fine in the Designer 7.1 but does not return any result if I put it onto the LC Forms Server 7.1 on RHEL 3.0.<br /><br />Appreciate and thank you for your help.<br /><br />-------------------------------------------------------------------<br />var sCol = xfa.datasets.data.nodes;<br />//for countries<br />var sColCountries = sCol.item(0).resolveNodes("countries");<br />var sColCountrys = sColCountries.item(0).resolveNodes("country[*]");<br />for(i=0;i<sColCountrys.length;i++){<br /> myform.DropDownList1.addItem(sColCountrys.item(i).value);<br />}<br />-------------------------------------------------------------------<br />xml structure<br />-------------------------------------------------------------------<br /><?xml version="1.0" encoding="ISO-8859-1"?> <br /><masterdata><br /> <countries><br /> <country>Australia</country><br /> <country>Bhutan</country><br /> <country>China</country><br /> <country>United States</country><br /> </countries><br /> <qualifications><br /> </qualifications><br /></masterdata><br />-------------------------------------------------------------------<br />Regards,<br />Praveen

Avatar

Former Community Member
Again, I have to ask if your passing in your XML data in the data parameter of the renderForm() method? If so, then what event of what object do you have your script on? I tried your XML and a form with your script here and it worked fine for me.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Hi Chris,



Apologize for not being straight to the point.



No, I am not pass the XML data in the data parameter of the renderForm() method for this task which is for populating dropdowns with master data because I am already using renderForm() method to pre-populate the form with the user data and as I understand we can not pass two XMLs to renderForm() method, hence looking for other possible options to pass the xml to the form server to populate the drop downs without having to create a data connection.



Appreciate and thank you for your time & help.



Regards,

Praveen

Avatar

Former Community Member
Well, you need to pass the XML in to be placed in the forms data DOM or else the script can't find it and populate the dropdowns. I'm assuming the values for the dropdowns aren't static and may change at any time and that's why your not hardcoding them into the form? Can you not combine the xml data for the drop downs and the user xml data into one DOM and pass that into renderForm?



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Chris,



Thank you so much for the reply, I also thought of the same option and working it.

Thanx

Praveen

Avatar

Former Community Member
Hi,<br /><br />sorry, here is yet another Adobe Designer beginners question:<br /><br />My form uses a webservice data connection which returns<br />an xml-string like this:<br /><br /><?xml version="1.0" encoding="utf-16"?> <br /><CurrentWeather> <br /> <Location>Sion, Switzerland (LSGS) 46-13N 007-20E 481M</Location> <br /> <Time>Apr 26, 2007 - 09:50 AM EDT / 2007.04.26 1350 UTC</Time> <br /> <Wind> from the WSW (240 degrees) at 15 MPH (13 KT):0</Wind> <br /> <Visibility> greater than 7 mile(s):0</Visibility> <br /> <SkyConditions> partly cloudy</SkyConditions> <br /> <Temperature> 80 F (27 C)</Temperature> <br /> <DewPoint> 46 F (8 C) </DewPoint> <br /> <RelativeHumidity> 30%</RelativeHumidity> <br /> <Pressure> 29.88 in. Hg (1012 hPa)</Pressure> <br /> <Status>Success</Status> <br /></CurrentWeather> <br /><br />What is the simplest and recommended way to extract the<br />element fields to my form?<br /><br />Thank you very much an kind regards,<br />Hans Grund

Avatar

Former Community Member
HI,



How can I import a XML file into pdf form.

I am using 8.0 acrobat reder basic version. but i am cannot do this.

I got some error messege when i going to create object of CacroApp the error is

[Retrieving the COM class factory for component with CLSID {85DE1C45-2C66-101B-B02E-04021C009402} failed due to the following error: 80040154.] i am using vs 2005 for programatically do import.



Any help will be appriciated.



thanks in advance.



Chavan Shahaji