Add Carriage Return to XML Output in Visual Basic

Author Message
bholmstrom

  • Total Posts : 10
  • Scores: 0
  • Reward points : 0
  • Joined: 10/15/2010
  • Location: NJ
  • Status: offline
Add Carriage Return to XML Output in Visual Basic Thursday, October 21, 2010 5:50 AM (permalink)
0
I need help getting the xml output to break up into sections like in the 2nd section (desired output)
 
I was more thinking of the code that would create a carriage return after each record….
 
Here is what the output looks like now ( below is what is desired)
 
<paysched>
            <parameters>
                        <title></title>
                        <loanamount>93456.91</loanamount>
                        <period>6</period>
                        <interest>0.1</interest>
                        <paytype>1</paytype>
                        <frequency>3</frequency>
                        <schedulesetup>-1</schedulesetup>
                        <firstpayment>15581.00</firstpayment>
                        <regpayment>15581.00</regpayment>
                        <lastpayment>15577.77</lastpayment>
                        <currentbalance>93456.91</currentbalance>
                        <startdate>20101121</startdate>
                        <diarycode>414</diarycode>
                        <diarydesc>DEBTOR OWES ME A PAYMENT</diarydesc>
                        <defaultdiarycode>414</defaultdiarycode>
                        <schedulechange>-1</schedulechange>
            </parameters>
            <schedule>
                        <record rec="1"><date>20101121 </date><payment>15581 </payment></record><record rec="2"><date>20101221 </date><payment>15581 </payment></record><record rec="3"><date>20110121 </date><payment>15581 </payment></record><record rec="4"><date>20110221 </date><payment>15581 </payment></record><record rec="5"><date>20110321 </date><payment>15581 </payment></record><record rec="6"><date>20110421 </date><payment>15577.77 </payment></record></schedule>
            <diary>
                        <diarydetails rec=" 1 ">
                                    <diarycode> 1 </diarycode>
                                    <diarydesc>New claim entered</diarydesc>
                        </diarydetails>
                        <diarydetails rec=" 999 ">
                                    <diarycode> 999 </diarycode>
                                    <diarydesc>Diary Code 999 - Last Closed Diary Code in system.</diarydesc>
                        </diarydetails>
            </diary>
</paysched>
 
 
This is the output desired:
 
<paysched>
            <parameters>
                        <title></title>
                        <loanamount>93456.91</loanamount>
                        <period>6</period>
                        <interest>0.1</interest>
                        <paytype>1</paytype>
                        <frequency>3</frequency>
                        <schedulesetup>-1</schedulesetup>
                        <firstpayment>15581.00</firstpayment>
                        <regpayment>15581.00</regpayment>
                        <lastpayment>15577.77</lastpayment>
                        <currentbalance>93456.91</currentbalance>
                        <startdate>20101121</startdate>
                        <diarycode>414</diarycode>
                        <diarydesc>DEBTOR OWES ME A PAYMENT</diarydesc>
                        <defaultdiarycode>414</defaultdiarycode>
                        <schedulechange>-1</schedulechange>
            </parameters>
            <schedule>
                        <record rec="1"><date>20101121 </date><payment>15581 </payment></record>
                        <record rec="2"><date>20101221 </date><payment>15581 </payment></record>
                        <record rec="3"><date>20110121 </date><payment>15581 </payment></record>
                        <record rec="4"><date>20110221 </date><payment>15581 </payment></record>
                        <record rec="5"><date>20110321 </date><payment>15581 </payment></record>
                        <record rec="6"><date>20110421 </date><payment>15577.77 </payment></record>
            </schedule>
            <diary>
                        <diarydetails rec=" 1 ">
                                    <diarycode> 1 </diarycode>
                                    <diarydesc>New claim entered</diarydesc>
                        </diarydetails>
                        <diarydetails rec=" 999 ">
                                    <diarycode> 999 </diarycode>
                                    <diarydesc>Diary Code 999 - Last Closed Diary Code in system.</diarydesc>
                        </diarydetails>
            </diary>
</paysched>
 
Here is the code that generates the output: (saving codes is below)
 
Private Sub SetValuesToXMLFile()
 
    OpenFlatFile
   
    Dim LinesFromFile As String, sNextLine As String
    Dim sFields(1 To 8) As String
   
    Print #mlFileNum, "<paysched>"
   
    Print #mlFileNum, "<parameters>"
   
    Print #mlFileNum, "<title>" & msTitle & "</title>"
    Print #mlFileNum, "<loanamount>" & mdLoanAmount & "</loanamount>"
    Print #mlFileNum, "<period>" & mlPeriod & "</period>"
    Print #mlFileNum, "<interest>" & mdRate & "</interest>"
    Print #mlFileNum, "<paytype>" & mlPayType & "</paytype>"
    Print #mlFileNum, "<frequency>" & mlFrequency & "</frequency>"
    Print #mlFileNum, "<schedulesetup>" & mbHasSchedule & "</schedulesetup>"
    Print #mlFileNum, "<firstpayment>" & mdFirstPayment & "</firstpayment>"
    Print #mlFileNum, "<regpayment>" & mdMonthlyPayment & "</regpayment>"
    Print #mlFileNum, "<lastpayment>" & 276.21 & "</lastpayment>"
    Print #mlFileNum, "<currentbalance>" & mdCurrentBal & "</currentbalance>"
    Print #mlFileNum, "<startdate>" & 20030723 & "</startdate>"
    Print #mlFileNum, "<diarycode>" & mlDiaryCode & "</diarycode>"
    Print #mlFileNum, "<diarydesc>" & msDiaryDesc & "</diarydesc>"
    Print #mlFileNum, "<defaultdiarycode>" & mlDiaryCode & "</defaultdiarycode>"
   
    Print #mlFileNum, "</parameters>"
   
    Dim lRecCounter As Long
    Dim sDate As String
    Dim sAmount As String
   
    If mbChanged Then
       
        Print #mlFileNum, "<schedule>"
           
        lRecCounter = 1
        With moRS
            .MoveFirst
       
            Do While Not .EOF
               
                Print #mlFileNum, "<record rec='" & CStr(lRecCounter) & "'>"
                Print #mlFileNum, "<date>" & .Fields("Date") & " " & "</date>"
                sAmount = Format(.Fields("Payment") & " ", "########0.00")
                Print #mlFileNum, "<payment>" & sAmount & "</payment>"
                Print #mlFileNum, "</record>"                                 
                lRecCounter = lRecCounter + 1
               
                .MoveNext
            Loop
           
        End With
       
        Print #mlFileNum, "</schedule>"
       
    End If
   
    Print #mlFileNum, "</paysched>"
   
End Sub
 
Here is the code that saves the output:
 
Private Sub SaveXMLRecords(ByVal oRecNode As IXMLDOMNode, ByVal oDocument As DOMDocument)
    'if mbChanged then delete all childnodes
    'loop through moRS and append nodes
    Dim oNode As IXMLDOMNode
    Dim lCount As Long
    Dim lRecCounter As Long
    Dim s As String
   
    ReadFieldNames
   
    If mbChanged Then
       
        For Each oNode In oRecNode.childNodes
            oRecNode.removeChild oNode
        Next oNode
       
        If mbHasSchedule Then
       
            lRecCounter = 1
            moRS.MoveFirst
           
            Do While Not moRS.EOF
               
                Dim oNewRec As IXMLDOMNode
                Set oNewRec = oDocument.createNode(1, "record", "")
                oRecNode.appendChild oNewRec
               
                Dim oAttrib As IXMLDOMNode
                Set oAttrib = oDocument.createAttribute("rec")
                oAttrib.Text = CStr(lRecCounter)
                oNewRec.Attributes.setNamedItem oAttrib
                Set oAttrib = Nothing
               
                For lCount = 1 To 2
                    Dim oNewNode As IXMLDOMNode
                    Set oNewNode = oDocument.createNode(1, msFieldNames(lCount), "")
                    If msFieldNames(lCount) = "Payment" Then
                        oNewNode.Text = Format(moRS.Fields(msFieldNames(lCount)) & " ", "########0.00")
                    Else
                        oNewNode.Text = moRS.Fields(msFieldNames(lCount)) & " "
                    End If
 
                    oNewRec.appendChild oNewNode
                   
                Next lCount
               
                moRS.MoveNext
                lRecCounter = lRecCounter + 1
            Loop
           
        End If      ' End  of mbhasSchedule
           
    End If          'End of mbChanged
       
End Sub
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9