XML File Toolbox -- The power of XML!
Why XML? More than just configuration files! 💪
In INI-Helper we looked at INI files -- a simple and proven solution for configuration management. Now it's time for the next level:
XML files!
Yes, INI files are great for simple settings. But as soon as your application grows, you'll quickly reach its limits:
• No hierarchical structures (only section → key → value)
• No data validation
• Limited international character support
• Not suitable for complex data structures
This is where XML comes in!
XML: Not just for configurations
XML is much more versatile than INI. Sure, you can use it for configurations -- but that's just the beginning:
• Hierarchical data structures: Perfect for nested configurations, catalogs, or product databases
• UTF-8 support: All languages, special characters, and even emojis -- no problem!
• Data exchange: XML is the standard for system integration
• Validation: Check structure and content with schemas
• Built-in: MSXML is available in every Windows installation
My conclusion: INI for simple cases, XML when you need power and flexibility!
🧰 The complete XML File Toolbox – 13 powerful functions!
I've developed a comprehensive VBA library that provides INI-like simplicity with the power of XML. All functions use Late Binding (no references required) and work in all Access versions (32/64-bit).
📖 1. XML_ReadValue - Read values
The basic function for reading configuration values.
strBackendPath = XML_ReadValue(strXmlPath, "Database", "BackendPath", "")
✍️ 2. XML_WriteValue - Write or update values
Saves values to the XML file. Automatically creates file and section if they don't exist! Special characters are automatically escaped.
XML_WriteValue strXmlPath, "Database", "BackendPath", strSelectedPath
🖨️ 3. XML_PrintAll - Print complete file
Displays the entire content formatted in the Immediate Window -- perfect for debugging!
XML_PrintAll CurrentProject.Path & "\config.xml"
📋 4. XML_GetSections - List all sections
Returns a collection of all sections.
Set colSections = XML_GetSections(strXmlPath)
For Each varSection In colSections
Debug.Print "Found Section: " & varSection
Next
🔑 5. XML_GetKeys - All keys of a section
Perfect for dynamic processing of all settings.
Set colKeys = XML_GetKeys(strXmlPath, "Database")
For Each varKey In colKeys
Debug.Print varKey & " = " & XML_ReadValue(strXmlPath, "Database", CStr(varKey))
Next
🗑️ 6. XML_DeleteSection - Delete entire section
Removes a complete configuration section.
If XML_SectionExists(strXmlPath, "OldModule") Then
XML_DeleteSection strXmlPath, "OldModule"
End If
❌ 7. XML_DeleteKey - Delete a key
Deletes specific settings.
XML_DeleteKey strXmlPath, "Session", "TempPassword"
✔️ 8. XML_SectionExists - Check section
Checks whether a configuration section exists.
If Not XML_SectionExists(strXmlPath, "DatabaseV2") Then ...
✅ 9. XML_KeyExists - Check key
Checks whether a specific setting exists.
If Not XML_KeyExists(strXmlPath, "Features", "AutoBackup") Then
XML_WriteValue strXmlPath, "Features", "AutoBackup", "True"
End If
🏗️ 10. XML_PrintStructured - Structured output
Displays the XML file in a hierarchical structure -- ideal for documentation!
XML_PrintStructured strXmlPath
📦 11. XML_GetAllValues - Dictionary of all values
Retrieves all key-value pairs of a section as a dictionary -- super efficient!
Set dictDB = XML_GetAllValues(strXmlPath, "Database")
Debug.Print "Server: " & dictDB("Server")
Debug.Print "Port: " & dictDB("Port")
Debug.Print "Timeout: " & dictDB("Timeout")
🔍 12. XML_ValidateFormat - Format validation
Checks the XML file for errors: malformed XML, duplicate keys, missing attributes.
If Not XML_ValidateFormat(strImportedXmlPath) Then
MsgBox "The imported configuration is invalid!", vbCritical
End If
Validation Checks:
- File exists and is readable
- XML is well-formed (correct syntax)
- No duplicate sections
- No duplicate keys within a section
- All sections and keys have names
🔄 13. XML_Compare - Compare two XML files
THE HAMMER for versioning and migration management!
If Not XML_Compare(strOldConfig, strNewConfig) Then
Debug.Print "Changes detected - see details in Immediate Window"
End If
Perfect for:
📊 Version comparison after updates
🔍 Troubleshooting configuration problems
📝 Documentation of changes
⚠️ Warning in case of critical deviations
🌍 Real-World Use Cases - Beyond Configuration
Use Case 1: Multi-Backend Support (Classic)
XML_WriteValue strXmlPath, "Backends", "Production", "\\Server\DB\Prod.accdb"
XML_WriteValue strXmlPath, "Backends", "Test", "\\Server\DB\Test.accdb"
XML_WriteValue strXmlPath, "Backends", "Development", "C:\Dev\DB.accdb"
XML_WriteValue strXmlPath, "Settings", "CurrentEnvironment", "Production"
Use Case 2: Product Catalog with Hierarchical Structure
XML is perfect for nested data! Example: A product catalog with categories, products, and attributes.
<?xml version="1.0" encoding="UTF-8"?>
<Product>
<Section name="Electronics">
<Key name="Laptop_001">Dell XPS 15, €1499, 16GB RAM</Key>
<Key name="Laptop_002">MacBook Pro, €2299, 32GB RAM</Key>
<Key name="Phone_001">iPhone 15, €999, 256GB</Key>
</Section>
<Section name="Books">
<Key name="Programming_001">Clean Code, €35.99</Key>
<Key name="Programming_002">Design Patterns, €42.50</Key>
</Section>
</Product>
Use Case 3: Export Templates for Reports
Store export settings (headers, formats, filters) in XML and load them dynamically.
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "Title", "Monthly Sales Report"
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "DateFormat", "DD.MM.YYYY"
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "Columns", "Date,Customer,Amount,Status"
XML_WriteValue strXmlPath, "ReportTemplate_Sales", "SortBy", "Amount DESC"
Use Case 4: User Preferences with UTF-8
Perfect for international applications! All special characters work flawlessly.
XML_WriteValue strXmlPath, "UI", "Language", "DE"
XML_WriteValue strXmlPath, "UI", "Theme", "Dark"
XML_WriteValue strXmlPath, "UI", "WelcomeMessage", "Willkommen zurück, Müller!"
XML_WriteValue strXmlPath, "Export", "DefaultFolder", "C:\Users\Marcus\Exporte"
Use Case 5: System Integration via XML
Exchange data with other systems that expect XML format (e.g., web services, ERP systems). The functions automatically create valid, well-formed XML that other systems can read!
✨ The Advantages at a Glance
✅ Update-proof: XML remains intact during frontend updates
✅ UTF-8 support: All languages and special characters work perfectly
✅ Robust: MSXML -- proven for decades
✅ Universal: Standard format for data exchange
✅ Hierarchical: Support for complex, nested structures
✅ 32/64-bit: Works in all Access versions
✅ No dependencies: Only MSXML (Late Binding), no references necessary
✅ Auto-escaping: Special characters (&, <, >, ", ') automatically handled
⚠️ Important: Special Characters Handling
The module automatically escapes all special characters. You don't have to worry about it!
Automatic handling:
XML_WriteValue strXmlPath, "Test", "Ampersand", "A & B" ' Saved correctly as "A & B" and read back as "A & B"
XML_WriteValue strXmlPath, "Test", "Quotes", "He said "Hello"" ' Automatically escaped, no problems!
🔮 What’s next?
In the next episode of this series, I will introduce similar tools that store, write, and read data in .yml format.
🧪 Try it out
Using my little testing form you can try the functions directly. This makes it easy to learn the functions step by step. Do you develop a lot with Access?
Then give it a try — I’m looking forward to your feedback or ideas for additional functions! 🚀
You will find the detailed description and all instructions directly in the code - well documented as usual.
DOWNLOAD
Version: 1.0 18th December 2025




