Ask Your Question
4

How can VB script be used to format XML?

asked 2023-05-25 14:58:07 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-25 15:01:01 +0000

lalupa gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-25 14:58:07 +0000

Seen: 16 times

Last updated: May 25 '23