Wednesday, 30 December 2015

XML : MS Access Database VBA ExportXML

I have two tables CR and RELEASE with relationship from CR (ID) to RELEASE (CRID) one to many.

CR (design):

  ID: key, unique  Description: text    

RELEASE (design):

  ID: key, unique  CRID: number, not unique  Name: text    

With the following VBA code, I am managed to export the tables to XML.

  Set objOrderInfo = Application.CreateAdditionalData  objOrderInfo.Add ("RELEASE")  Application.ExportXML ObjectType:=acExportTable, DataSource:="CR", _                        DataTarget:=pFileNAme, _                        AdditionalData:=objOrderInfo    

The exported XML is something like:

  <?xml version="1.0" encoding="UTF-8"?>  <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2015-12-09T09:34:28">  <CR>      **<ID>1</ID>**      <Description>Test</Description>      <RELEASE>          <ID>1</ID>          **<CRID>1</CRID>**          <Name>R2016</Name>      </RELEASE>      <RELEASE>          <ID>2</ID>          **<CRID>1</CRID>**          <Name>R2017</Name>      </RELEASE>  </CR>    

Note that CRID showed several times in the XML which is practically redundant. How to remove the CRID elements from RELEASE element in XML? Thanks,

No comments:

Post a Comment