Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VB script can be used to format XML by using the Microsoft XMLDOM parser. Here is a sample VB script that formats XML:

Dim xmlDoc
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load("C:\path\to\file.xml")

xmlDoc.documentElement.setAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
xmlDoc.documentElement.setAttribute "xsi:noNamespaceSchemaLocation", "path/to/schema.xsd"

xmlDoc.documentElement.setAttribute "attribute1", "value1"
xmlDoc.documentElement.setAttribute "attribute2", "value2"

xmlDoc.documentElement.appendChild xmlDoc.createComment("This is a comment")

xmlDoc.save("C:\path\to\formatted\file.xml")

This code opens an XML file, sets some attributes and adds a comment before saving the modified XML file. The resulting XML file will be formatted with proper indentation and spacing for readability.