I'm totally new to XML; I just started to study something for my culture using VB6 (! I know... !), without a real goal at the moment. In my first attempt I got a surprising good result, but there is a minor problem which only impact on the visual output. The first line of the XML file is a standard preamble: ?xml version="1.0" encoding="iso-8859-1"?
. The second line is the node DB
info and it should follow the preamble on a new line, in this way:
<?xml version="1.0" encoding="iso-8859-1"?>
<DB>Created on 15/06/2021</DB>
But instead this second line continues on the first. I tried to insert a text node with a newline (as seen on this site), but I get an error, which translated, say something as: "'impossible to execute the operation with a node of type PCDATA". My code is:
Sub MakeDB()
Dim dom As MSXML2.DOMDocument60
Dim root As IXMLDOMElement
Dim node As MSXML2.IXMLDOMNode
Set dom = New MSXML2.DOMDocument60
dom.async = False
dom.preserveWhiteSpace = True
Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='iso-8859-1'" + vbNewLine)
dom.appendChild node
Set node = Nothing
'the following lines raise the error
Set node = dom.createTextNode(vbNewLine)
dom.appendChild node
Set node = Nothing
' Create the first element.
Set root = dom.createElement("DB")
Set node = dom.createTextNode("Created on " + CStr(Date))
root.appendChild node
Set node = Nothing
dom.appendChild root
...
I realize that this is not a real problem, but I would like to understand what happens.