logo
search
File Format & Compatibility

How to Export a Custom XML Structure from Microsoft Access

John WilsonJohn Wilson Oct 19, 2026 869 views

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.

How to Export a Custom XML Structure from Microsoft Access
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.
Before you start

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.

Solution 1Recommended

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.

1
Add the MSXML Reference

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.

2
Initialize the DOM Document

In your VBA module, declare and instantiate a new DOMDocument object using 'Dim xmlDoc As New MSXML2.DOMDocument60'.

3
Build Elements and Attributes

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.

4
Save the XML Document

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.

Generate Custom XML Programmatically Using MSXML DOM
Reliable Parsing: Using the DOM ensures your output is well-formed XML, automatically escaping special characters and avoiding syntax errors.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install WPS Office: Run the downloaded installation file and follow the straightforward on-screen instructions to set up the software.
  3. 3. Open Your Exported Files: Launch WPS Office to easily open, edit, and analyze CSV or XML data exported from your database.
Free and lightweight alternative to Microsoft OfficeFully compatible with Microsoft Excel (.xlsx), Word (.docx), and PowerPoint (.pptx)Intuitive tabbed interface to manage multiple documents in one windowSeamless integration for viewing data exported from enterprise databases
microsoft office alternative - wps office

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.