Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xmlAdapter with Append From, to a batch of files

Status
Not open for further replies.

peteschulte

IS-IT--Management
Nov 21, 2008
41
US
Thanks to Olaf, Tamar, Stfaprc, MikeLewis and others
smiletiniest.gif

I've arrived at the question how to use xmlAdapter and append from its tables collection to a batch of files. Some of their data types have been converted from Memo.

There's more background and detail in thread 184-1517016 "xmlToCursor()--how to use?" This new thread recaps what I posted onto the end of that one yesterday, since it created no response.

Also, I have searched Tek-Tips VFP Forum through several pages on "Append From." So I will appreciate any assistance that works!

Here is the original module that works well, but results in tables with too many memo fields. It's followed by my program development language, trying to code a match between the xmlAdapter tables and the folder of tables.
Code:
SET DEFAULT TO \\Gmc\d\Stmt\Monterey\UB_Test_1231
Local lcXML, loXMLAdapter, loXMLTable
Close Tables All

xmlfile="BPtestXML.txt"
xmlcontent = FILETOSTR(xmlfile)
lcXML = xmlcontent 

loXMLAdapter = CreateObject("XMLAdapter")

loXMLAdapter.LoadXML(lcXML,.F.,.T.)
&& XMLAdapter.LoadXML( cXMLDocument [, lFile [, lValidateOnParse ]] )

For Each loXMLTable in loXMLAdapter.Tables
   loXMLTable.ToCursor()
  	COPY TO (loXMLTable.Alias+".dbf")
ENDFOR

SET

PDL
Code:
Set default DIR

(Other code precedes this)

For Each loXMLTable in loXMLAdapter.Tables

	IF loXMLTable.Alias is contained in string (file name list)

		USE table from file list
		APPEND FROM loXMLTable.Alias
	ELSE
		WAIT 'File not found' WINDOW TIMEOUT 200
	
	ENDIF

ENDFOR

Here is the list of files to append to.
They are in \\Gmc\d\Stmt\Monterey\UB_Test_1231\RevisedDataTypes. This list would also form the string to search for xmlAdapter.alias table name "is contained in."

ACCOUNT.DBF, agencyinfo.dbf, BILLINGSUMMARY.DBF, billingsummarydetail.dbf,
BILLSUMMARY.DBF, consumptionhistory.dbf, customer.DBF, fees.dbf,
locationsummary.dbf, mailto.dbf, meterhistory.dbf, notessummary.DBF,
service.dbf, trans.DBF.

Standing by,
smiletiniest.gif

Peter
 
Peter - I don't understand what your question is. What's the specific task you need help with?

Tamar
 
Hi Tamar,
How do I "use xmlAdapter and append from its tables collection to a batch of files"?

That is, for each loXMLTable in loXMLAdapter.Tables, find it's name matched in the list of file names from the folder, and

write the xml from one loXMLAdapter.Tables table to that matched table in the folder,

then check for the next in loXMLAdapter.Tables and repeat.

My idea of a method is to put all of the table names into a string. Then check for each loXMLTable.Alias $ string. If contained in string, then use that table which is already data-typed in the folder and append from loXMLTable.Alias.

It was xmlAdapter that previously created these tables, so I know that the file names in the folder match loXMLAdapter.Tables. The idea is to append to existing tables, which will preserve data types rather than use Memo.

I was in a meeting, but now I'm standing by again for 3 hours or so.
smiletiniest.gif

Thank you
 
I'm still not exactly sure what you're trying to do, but I'll give you a few ideas.

First, to find the list of tables in a particular folder, use the ADIR() function:

* Assuming you're in the right folder
LOCAL aFiles[1], nFileCount
nFileCount = ADIR(aFiles, "*.DBF")

Now you have an array where each row represents one DBF.

Second, with XMLAdapter, I'm not sure why you need to do this at all. Can't you just pass the appropriate parameters to the ToCursor method to add the data to an existing table?

Tamar
 
Hi Tamar,

Tamar said:
Can't you just pass the appropriate parameters to the ToCursor method to add the data to an existing table?

Yes, that's exactly what Pete did not know.

Also see the reactivated thread in General Coding Issues - thread184-1517016.

Bye, Olaf.
 
Tamar and Olaf, thank you,
smiletiniest.gif

I'll check it out and report results!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top