rp_data::importfromxml

Imports data from an xml file

o.importfromxml( tcFileName, tcMatchonExpression ,tcDefaultValueRecord, tcImportIDField, tcIgnoreFields, tcXMLNode)

Return Value

True or False

Parameters

tcFileName
The full path to the DBF file containing the data to be imported

tcMatchonExpression
This is an expression that can be used to uniquely identify records in the data
file which match the records being imported. This is used when PK values are
not provided in the import file.

tcDefaultValueRecord
If there is an existing record in the system which holds defualt values which
you want applied to each record being imported then this should be the PK value
of that record.

tcImportIDField
Not used in this method yet

tcIgnoreFields
In some cases you may want ignore fields in the import file. It may have the same name
as a field in the table to which data is being imported but it should not be applied to
that field. Provide a comma deleimited list of these fields here.

Remarks

This method is very handy for importing data. This method is supported by the asynchserver
so it can be performed asynchronously. The logic it follows is as follows

1. It checks that the PK field is present in the import file. The program will place data
On existing recorsds if PK values are supplied. If Not then new records are created. The
new PK values will be written into the import file for your reference.

2. It scans through file and will locate existing records by matching PK values if provided
or by matching existing records based on the provided tcMatchonExpression paramter. If a match
is found based on this query the first match is used. For example if we are importing to a table
which has fields called account and system, we could provide a tcMatchonExpression value of

"account == {account} and system == {system}"

notice that the curly brackets are used to denote fields in the import table.

3. After either loading an existing record or creating a new record, it will apply
any non empty values of the default record if a PK value for one is provided in the
tcDefaultValueRecord parameter.

4. It then applies values of all matching fields in the import table.

5. It then saves the record.

6. It then writes the PK value of this record back to the PK field in the import table.


The xml fle would have the following structure and will NOT contain a schema

<?xml version="1.0" encoding="UTF-8" ?>
- <routeSet>
<route account="13801912" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR" />
<route account="13802021" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802131" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802240" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802349" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802458" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802568" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802677" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
<route account="13802896" day="TU" day_Number="3" route_Num="601" schedule="11" system="GAR"/>
</routeSet>

Example

o.ImportFromXML("C:\ROUTES\NEWROUTES.xml","account == {account} and system == {system}")

This would;
1.	Work the through the import file record by record
2.	If a pk value is not provided it will look for an existing route record by performing
	the following query
	SELECT ID WHERE account == {account} and system == {system}
	If no match is found then a new record is created
3.	Update the record with the new information
4.	Save the record

This method is supported by the jobserver.  Hence if you want this method submitted to the Job
Server table you need to set the property o.lsubmitasasynchprocess to True before
calling this method and the Job will be submitted and not run.  It is up to the user to then
run this job using the itrdsjobserver.

See also:

Class rp_data


Last Updated: 23/11/2005