VB 6.0 XML Output File Not Containing line feed character

I have written an application that opens an existing XML file. My software is written in VB 6.0 I am able to read the xml file, perform my needed tasks and then write my changes to the xml file. The error that I keep getting is when I append new children to the xml file I don't think I am getting any line feed characters to the xml. When I open the changed xml file with notepad I get changes that look like this

Existing XML file....
                <parentNodeIamAttachingTo>
                    <existingChild>ExistingData</existingChild>
                    <existingChild2>ExistingData</existingChild2>
                    <myNewChild>MyNewData</myNewChild><myNewChildsChild>itsData</myNewChildsChild><myNewChild2>myNewData</MyNewChild2></parentNodeIamAttachingto>
More Existing XML file...

What I want is output that look like this
                <parentNodeIamAttachingTo>
                    <existingChild>ExistingData</existingChild>
                    <existingChild2>ExistingData</existingChild2>
                    <myNewChild>MyNewData</myNewChild>
                        <myNewChildsChild>itsData</myNewChildsChild>
                    <myNewChild2>myNewData</MyNewChild2>
                </parentNodeIamAttachingto>

I am using MSXML2.DOMDocument40 and I am attaching my nodes with appendChild
sld9tAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

watyCommented:
' #Mandix Repository#*****************************************************
' * Programmer Name  : J R
' * Web Site         : http://www.vbdiamond.com
' * E-Mail           : vb_questions@swbell.net
' * Date             : 06/07/2001
' **********************************************************************
' * Comments         : Format XML it with indented nodes
' *
' * This simple shunk of code uses MSXML 3.0 to take any well-formed
' * XML file specified on the command line and format it with indented
' * nodes. Always creates paired tags, even for empty nodes, with
' * the exception of text and CDATA nodes.
' *
' **********************************************************************

'---------------------------------------------------------------------
' MSXML3 node type constants used in code
Const NODE_TEXT = 3
Const NODE_CDATA_SECTION = 4
'---------------------------------------------------------------------
'---------------------------------------------------------------------
' XML indentation formatting program
'---------------------------------------------------------------------
' Send any questions about this code to:
' vb_questions@swbell.net
' and I'll try to get back to you as quick as I can
'---------------------------------------------------------------------
'---------------------------------------------------------------------
' Make sure we don't use anything we didn't declare
Option Explicit
'---------------------------------------------------------------------
' MSXML3 node type constants used in code
Const NODE_TEXT = 3
Const NODE_CDATA_SECTION = 4
'---------------------------------------------------------------------
Public Sub Main()
   Dim bLoaded          As Boolean
   Dim strFileName      As String
   Dim strDTDFileName   As String
   Dim strStandalone    As String
   Dim xmlDoc           As New DOMDocument
   Dim nodeRoot         As IXMLDOMNode
   Dim strRootNodeName  As String
   Dim fsoFileSys       As New FileSystemObject
   Dim tstrXMLOut       As TextStream
   Dim strXMLOut        As String
   '-----------------------------------------------------------------
   'this is not a robust way to get the command line,
   'support for quotation marks should be added if you care,
   'something else to add is an optional second parameter for the DTD filename
   strFileName = Trim(Command)
   'attempt to load the file into the XML DOM document
   bLoaded = xmlDoc.Load(strFileName)
   If bLoaded Then
      Set tstrXMLOut = fsoFileSys.OpenTextFile(strFileName, ForWriting, True)
      Set nodeRoot = xmlDoc.documentElement
      strRootNodeName = nodeRoot.nodeName
      'get the formatted XML string
      strXMLOut = FormatNodeAsString(nodeRoot)
      'cleanup
      Set nodeRoot = Nothing
      Set xmlDoc = Nothing
      strStandalone = "no"
      'code assumes here that there is a DTD file of the same base name as the actual XML file
      strDTDFileName = Left(strFileName, Len(strFileName) - 4) & ".dtd"
      'build the necessary lines for any validXML file
      tstrXMLOut.WriteLine "<!-- <?xml version=" & """" & "1.0" & """" & " standalone=" & """" & strStandalone & """" & "?> -->"
      tstrXMLOut.WriteLine "<!-- <!DOCTYPE " & strRootNodeName & " SYSTEM " & """" & strDTDFileName & """" & "> -->"
      'write out the newly formatted XML string
      tstrXMLOut.Write strXMLOut
      tstrXMLOut.Close
      'more cleanup
      Set tstrXMLOut = Nothing
      Set fsoFileSys = Nothing
      'oh goody, we're done
      MsgBox "Success. " & strFileName & " has been formatted.", , "Format Complete"
   Else
      MsgBox "Couldn't load the XML file: " & strFileName & vbCrLf & "I quit!", , "File Error"
   End If
End Sub

' This function recurses through the XMLtree given in the nodeIn parameter
' generally this would be the root node,at least that's how I call it but
' it would work to format any subtree aswell
Private Function FormatNodeAsString(nodeIn As IXMLDOMNode, Optional intIndent As Integer = 0) As String
   Dim I                As Integer
   Dim strXML           As String
   Dim bChildIsTextOrCDATA As Boolean
   Dim intDent          As Integer
   intDent = intIndent
   Dim nodemapAttributes As IXMLDOMNamedNodeMap
   Dim nodelistChildren As IXMLDOMNodeList
   Dim nodeTempChild    As IXMLDOMNode
   Dim lngNodeType      As Long
   lngNodeType = nodeIn.nodeType
   Dim strNodeVal       As String
   strNodeVal = nodeIn.nodeTypedValue
   Dim bHasChildren     As Boolean
   '-------------------------------------------
   If lngNodeType = NODE_CDATA_SECTION Then
      strXML = strXML & "<![CDATA["
   ElseIf lngNodeType = NODE_TEXT Then
      'do nothing
   Else
      For I = 1 To intDent
         strXML = strXML & vbTab
      Next I
      strXML = strXML & "<" & nodeIn.nodeName
   End If
   Set nodemapAttributes = nodeIn.Attributes
   If Not (nodemapAttributes Is Nothing) Then
      For I = 0 To nodemapAttributes.length - 1
         Set nodeTempChild = nodemapAttributes.Item(I)
         strXML = strXML & " " & nodeTempChild.nodeName & "=" & """" & nodeTempChild.nodeTypedValue & """"
      Next I
   End If
   Set nodemapAttributes = Nothing
   If (lngNodeType <> NODE_CDATA_SECTION) And (lngNodeType <> NODE_TEXT) Then
      strXML = strXML & ">"
   End If
   Set nodelistChildren = nodeIn.childNodes
   bHasChildren = False
   If nodelistChildren.length > 0 Then
      bHasChildren = True
      Set nodeTempChild = nodelistChildren.Item(0)
      If Not ((nodeTempChild.nodeType = NODE_CDATA_SECTION) Or (nodeTempChild.nodeType = NODE_TEXT)) Then
         strXML = strXML & vbCrLf
         bChildIsTextOrCDATA = False
      Else
         bChildIsTextOrCDATA = True
      End If
      Do Until nodeTempChild Is Nothing
         strXML = strXML & FormatNodeAsString(nodeTempChild, intDent + 1)
         Set nodeTempChild = nodeTempChild.nextSibling
      Loop
   Else
      strXML = strXML & strNodeVal
   End If
   Set nodelistChildren = Nothing
   Set nodeTempChild = Nothing
   If lngNodeType = NODE_CDATA_SECTION Then
      FormatNodeAsString = strXML & "]]>"
   ElseIf lngNodeType = NODE_TEXT Then
      FormatNodeAsString = strXML
   Else
      If bHasChildren And (Not bChildIsTextOrCDATA) Then
         For I = 1 To intDent
            strXML = strXML & vbTab
         Next I
      End If
      FormatNodeAsString = strXML & "</" & nodeIn.nodeName & ">" & vbCrLf
   End If
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sld9tAuthor Commented:
Thanks for the ideas J R. Looking over your comments, you are suggesting reprocessing the final xml and restructuring it as an external file. I would like to avoid this if possible I see it being inefficient. I hope that MS has some method built into their xml controls that would allow you to save the xml file with indentation and line feed characters.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.