How to: XML Resource to string field instead of file

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
Vanessa
Forum Admin
Forum Admin
Posts: 34
Joined: Thu Sep 06, 2007 4:23 pm
Location: Sandy, UK
Contact:

How to: XML Resource to string field instead of file

#1

Postby Vanessa » Thu Jan 17, 2008 11:39 am

This is a question we were recently asked by a customer:

PROBLEM
I wish to insert the contents of an XML file into a database column, but the XML resource only read/writes to a file.

I could use a resource (have to create it first) to read in a textfile and have it read the contents into a textarea field. Next use a database resource to insert it into the DB. Next delete the (temporary) xml file. But what maxlength should the field have? When I wish to read the XML, I have to first create the temporary XML and read it in again.

I wonder if there is a method to do this in one go? I.e. writing / reading a XML file into / from the database.

SOLUTION
This is achieved by using the copy adapter within an xml resource. Here are the steps:

1. Within the resource, open the document by clicking on Documents

2. In the document panel, right click on the root element and click Attach Field - If your root element is called myDoc, this step will create a resource field called myDoc and attach it to the element

3. Create a new document called myDocCopy

4. Add a node to this new document called myDocString, make sure it is of type string

5. Just as in step 2, right click on the myDocString and click Attach Field - this step will create a resource field called myDocString and attach it to the element

6. Create a copy adapter, called say copy_mydoc, with myDoc as source and myDocString as destination and with checkbox "Escape destination XML into a single text value" checked

7. Save the xml resource

8. Create a text/textarea field in your form, large enough to take the longest xml you ever expect, map this field to the myDocString of the xml resource

9. The FPL is:

Code: Select all

update xmlresource; // to get the data from the form into the resource
call xmlresourse 'copy_mydoc'; // note quotes around adapter name
fetch xmlresourse; // to get the data from the resource into the form
10. Now you have a field in your form containing your XML document, which you can map to a database resource as you wish.
0 x

Who is online

Users browsing this forum: No registered users and 54 guests