Earlier today I wrote a blog post XMLPort: Export from temporary tables. The principle is the same when you want to import to a temporary table. Instead of calling a function in XMLPort before you call the export that inserts values into the temporary table you do the opposite, call a function after the import has completed that copies all the temporary data to your temporary record parameter. Create the XMLPort in the same way and don’t forget to mark the table as temporary.
Create a function in the XMLPort that fetches the imported data and copies it to the parameter.
PROCEDURE GetTemporaryRecord@1000000002(VAR TemporaryItem@1000000000 : Record 27);
BEGIN
//Copy all the temporary records to the new temporary variable
IF Item.FINDSET THEN REPEAT
TemporaryItem := Item;
TemporaryItem.INSERT;
UNTIL Item.NEXT = 0;
END;
Here is the test function that I use to call the XMLPort.
PROCEDURE ImportXMLToTempRecords@1000000013();
VAR
TemporaryItemXMLPort@1000000003 : XMLport 69782;
TempItem@1000000004 : TEMPORARY Record 27;
TestFile@1000000002 : File;
Instream@1000000001 : InStream;
FileName@1000000000 : Text[100];
BEGIN
//Builds data in temporary records and uses a XMLport with the temporary property to export the
//temporary records as XML
FileName := 'C:\temp\TESTXML.txt';
TestFile.OPEN(FileName);
TestFile.CREATEINSTREAM(Instream);
TemporaryItemXMLPort.SETSOURCE(Instream);
TemporaryItemXMLPort.IMPORT;
TemporaryItemXMLPort.GetTemporaryRecord(TempItem);
TestFile.CLOSE;
IF TempItem.FINDSET THEN
MESSAGE('Found the imported records, count=%1',TempItem.count)
ELSE
ERROR('Couldn't find the imported records');
END;
Here is the XML that I’m importing (export from my previous blog post)
<?xml version="1.0" encoding="UTF-16" standalone="no"?> <NAVItems> <NAVItem> <No>1</No> <Description>Test1</Description> </NAVItem> <NAVItem> <No>2</No> <Description>Test2</Description> </NAVItem> </NAVItems>
Brian Blackstone
2015-09-08 at 06:26
YES! This is exactly what I’ve been looking for! I missed it because of the simplicity! I couldn’t figure out how to get the temporary table data back from the XMLPort import, without writing it to a real table first. Creating a GetTemporaryData function fixes that. Thank you so much!
LikeLike