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