Question : How to export data from various tables into a single xml file

Hi Access experts,

I need to construct an xml file that takes it's data from several tables. The data consists mainly of order header information, order detail information , customer details, ship to address etc. This data is held in separate tables and I'm ok with gathering the data using ado or dao. What I'm stuck with is knowing how to inject this data into a well constructed hierarchical xml file as per the attached example. I know that you can quiet export tables of data as xml files but this method is to regular for the sort of thing I need to achieve. The XML file (see attached) that I need to achieve requires a fair bit of hierarchical nesting. The example attached shows one order request but several order requests could be required in the one file.
If you could point me in the right direction or give some real examples that would be greatly appreciated.

Thanks in advance,

Joe

Answer : How to export data from various tables into a single xml file

Hi,

you could do this with the SHAPE command in ADO. The method can be easily found by entering "XML" in the Access help (in my case Access 2007).

A nearly equal instruction can be found in the MSDN here:
http://msdn.microsoft.com/en-us/library/ms675843%28VS.85%29.aspx

You will find a Visual Basic example there which can also be used with ADO in VBA.

A "one-liner" example from the Access help:

Rs.Open "SHAPE {select stor_id, stor_name, state from stores} APPEND ({select stor_id, ord_num, ord_date, qty from sales} AS rsSales RELATE stor_id TO stor_id)", "Provider=MSDataShape;DSN=pubs;UID=MyUserId;PWD=MyPassword;"

If you have a SQL Server backend database you can do SELECTs with "FOR XML Auto" for example (and a lot other XML methods).

Cheers,

Christian

Random Solutions  
 
programming4us programming4us