This xbasic script creates XML output from any table(s) you include in the variable TBLS. The output is for ALL fields in the table, and has this structure:
HTML Code:
<Records> <Table1Name> <FieldA>myvalue</FieldA> <FieldB>myvalue</FieldB> <Table1Name> <Table2Name> <FieldA>myvalue</FieldA> <FieldB>myvalue</FieldB> <Table2Name> </Records>
HTML Code:
'Date Created: 22-Dec-2007 09:27:29 AM 'Last Updated: 22-Dec-2007 09:38:57 AM 'Created By : Steve Wood 'Updated By : Steve Wood 'GENERAL UTILITY TO WRITE ALL TABLE RECORDS TO XLM OUTPUT 'ASSUMES ALL TABLES ARE FILTERED ON THE SAME KEY FIELD AND FILTER VALUE 'OUTPUT USES THE TABLE NAMES AS XML ELEMENT TAGS dim myfilter as c dim lst as c 'THIS IS MY TEST VALUE, REMOVE OR REPLACE WITH YOUR OWN myfilter = "1106061328004846246" 'test value 'NAME THE OUTPUT FILE xmlfile = "c:\records.xml" 'LIST YOUR TABLE HERE. tbls = <<%txt% tr_trust_master tr_childbene %txt% 'CODE BELOW CREATES OUTPUT. 'CHANGE 'RECORDS' TO ANOTHER VALUE IF APPROPRIATE 'NOTE MY FILTER IS BASED ON JOBID, CHANGE TO FIT YOUR SITUATION lst = "<Records>" + crlf() for each i in tbls tbl=table.open(i) query.filter = "Job_Id=" + s_quote(myfilter) query.order = "Job_Id" query.options = "T" tbl.fetch_first() indx = tbl.query_create() WHILE .not. tbl.fetch_eof() lst = lst + " <" + i + ">" + crlf() flds=tbl.field_name_get() FOR each foo in flds fld = tbl.field_get(foo) v = fld.value_get() g = " <"+foo+">"+alltrim(v)+"</"+foo+">" lst = lst + g + crlf() next lst = lst + " </" + i + ">" + crlf() tbl.fetch_next() END WHILE indx.close() tbl.close() tbl.query_detach() next lst = lst + "</Records>" save_to_file(lst,xmlfile)
Comment