How to Export a Custom XML Structure from Microsoft Access
Question details
The user needs to export data into a specific custom XML structure from Microsoft Access, but the default export method does not support generating nested elements and attributes like ExtendedData or SchemaData.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Exporting query results into a highly customized XML file with specific tags and nested structures instead of the default database schema.
- Observed behavior
- The native Application.ExportXML method automatically exports using Access-generated element names and cannot directly create advanced custom structures with attributes and nested data.
Ensure you have basic familiarity with writing VBA (Visual Basic for Applications) code in Microsoft Access and know the exact XML schema layout you need to generate.
Generate Custom XML Programmatically Using MSXML DOM
Use the Microsoft XML Core Services (MSXML) library in VBA to accurately build and structure complex nested elements and attributes.
The MSXML Document Object Model (DOM) provides precise programmatic control over your XML file. This is the most reliable method for constructing specific tags like ExtendedData, SchemaData, and SimpleData.
Open the VBA Editor in Access (Alt + F11). Click on 'Tools' > 'References', then scroll down and check 'Microsoft XML, v6.0' (or the latest version available), and click OK.
In your VBA module, declare and instantiate a new DOMDocument object using 'Dim xmlDoc As New MSXML2.DOMDocument60'.
Use 'xmlDoc.createElement' to create your custom tags and 'xmlDoc.createAttribute' for attributes. Loop through your Access query recordset to append these child nodes to your root structure dynamically.
Once the entire custom tree is built in memory, use the 'xmlDoc.Save("C:\path\to\your\file.xml")' method to export the final XML file to your computer.

Write XML Manually Using a VBA TextStream Object
Use the FileSystemObject in VBA to manually construct and write out the exact XML strings line-by-line to a text file.
Need a Fast, Free Office Suite Alternative?
While WPS Office does not feature a direct Microsoft Access database equivalent, it provides a powerful, lightweight, and completely free alternative for all your Word, Excel, and PowerPoint needs. If you work with exported data in spreadsheets or reports, WPS Spreadsheet is the perfect companion.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded installation file and follow the straightforward on-screen instructions to set up the software.
- 3. Open Your Exported Files: Launch WPS Office to easily open, edit, and analyze CSV or XML data exported from your database.

Frequently Asked Questions
Can I customize element names when using Application.ExportXML in Access?
No, the built-in Application.ExportXML method automatically generates element tags based on the table or query names being exported. It cannot natively generate external schemas. You must write VBA code to achieve this.
What is the MSXML library used for in Microsoft Access?
MSXML (Microsoft XML Core Services) is a library that provides the Document Object Model (DOM). It allows developers to programmatically create, parse, navigate, and manipulate XML documents safely within VBA.
How do I export Access data to XML without using VBA code?
You can use the built-in export wizard by navigating to 'External Data' > 'XML File'. However, this will strictly export the data using the default schema generated by Access, which will not work if you require a highly specific custom layout.




