aadebayo 0 Newbie Poster

Hello

I am currently writing a program that generates an XML file. I am having some minor difficulty. I need it to look like below

<?xml version="1.0"?>
<?xml-stylesheet type='text/xml' href='test.xsl'?>
<!--sample xml file created using XML DOM object.-->
<GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
	<EnvelopeVersion>2.0</EnvelopeVersion>
	<Header><![CDATA[<some mark-up text>]]></Header>
	<node3>
		<subNode1/>
		<subNode2/>
		<subNode3/>
	</node3>
</GovTalkMessage>

however, when I run it, it looks like below, I do not want the bold bits

<?xml version="1.0"?>
<?xml-stylesheet type='text/xml' href='test.xsl'?>
<!--sample xml file created using XML DOM object.-->
<GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
	<EnvelopeVersion[B] xmlns=""[/B]>2.0</EnvelopeVersion>
	<Header [B]xmlns=""[/B]><![CDATA[<some mark-up text>]]></Header>
	<node3 [B]xmlns=""[/B]>
		<subNode1/>
		<subNode2/>
		<subNode3/>
	</node3>
</GovTalkMessage>

here is the code that I am using

Private Function CreateDOM()
    Dim dom
    Set dom = New DOMDocument30
    dom.async = False
    dom.validateOnParse = False
    dom.resolveExternals = False
    dom.preserveWhiteSpace = True
    Set CreateDOM = dom
End Function

Private Sub Form_Load()
    Dim dom, node, attr, header

    On Error GoTo ErrorHandler

    Set dom = CreateDOM
    
    ' Create a processing instruction targeted for xml.
    Set node = dom.createProcessingInstruction("xml", "version='1.0'")
    dom.appendChild node
    Set node = Nothing
    
    ' Create a processing instruction targeted for xml-stylesheet.
    Set node = dom.createProcessingInstruction("xml-stylesheet", _
                                "type='text/xml' href='test.xsl'")
    dom.appendChild node
    Set node = Nothing
    
    ' Create a comment for the document.
    Set node = dom.createComment("sample xml file created using XML DOM object.")
    dom.appendChild node
    Set node = Nothing
    
    ' Create the GovTalkMessage element.
    Dim GovTalkMessage, EnvelopeVersion
    Set GovTalkMessage = dom.createElement("GovTalkMessage")
    
    ' Create a "xmlns" attribute for the GovTalkMessage element and
    ' assign the "http://www.govtalk.gov.uk/CM/envelope" character data as the attribute value.
    Set attr = dom.createAttribute("xmlns")
    ' Set attr = dom.createAttribute("Created")
    attr.Value = "http://www.govtalk.gov.uk/CM/envelope"
    GovTalkMessage.setAttributeNode attr
    Set attr = Nothing
    
    
    ' Add the GovTalkMessage element to the DOM instance.
    dom.appendChild GovTalkMessage
    ' Insert a newline + tab.
    GovTalkMessage.appendChild dom.createTextNode(vbNewLine + vbTab)
    ' Create and add more nodes to the GovTalkMessage element just created.
    ' Create a text element.
    Set EnvelopeVersion = dom.createElement("EnvelopeVersion")
    EnvelopeVersion.Text = "2.0"
    ' Add text node to the GovTalkMessage element.
    GovTalkMessage.appendChild EnvelopeVersion
    Set EnvelopeVersion = Nothing
      ' Add a newline plus tab.
    GovTalkMessage.appendChild dom.createTextNode(vbNewLine + vbTab)
    
    ' Create an element to hold a CDATA section.
    Set header = dom.createElement("Header")
    Set cd = dom.createCDATASection("<some mark-up text>")
    header.appendChild cd
    Set cd = Nothing
    dom.documentElement.appendChild header
      ' Add a newline plus tab.
    GovTalkMessage.appendChild dom.createTextNode(vbNewLine + vbTab)
    
    Set header = Nothing
    ' Create an element to hold three empty subelements.
    Set node = dom.createElement("node3")
    
    ' Create a document fragment to be added to node3.
    Set frag = dom.createDocumentFragment
        ' Add a newline + tab + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
    frag.appendChild dom.createElement("subNode1")
       ' Add a newline + tab + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
    frag.appendChild dom.createElement("subNode2")
       ' Add a newline + tab + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
    frag.appendChild dom.createElement("subNode3")
       ' Add a newline + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab)
    node.appendChild frag
    Set frag = Nothing
       dom.documentElement.appendChild node

    GovTalkMessage.appendChild node
       ' Add a newline.
    GovTalkMessage.appendChild dom.createTextNode(vbNewLine)
    Set node = Nothing
    
    ' Save the XML document to a file.
    dom.save App.Path + "\dynamDom.xml"
    Set GovTalkMessage = Nothing
    Set dom = Nothing
    Exit Sub
    
ErrorHandler:
    MsgBox Err.Description
End Sub