如何在循环时将回车符添加到xml输出 [英] How to add a carriage return to an xml output while looping
问题描述
我们有一个程序可以循环x次(基于付款编号)
当到达每条记录时,我们希望VB代码在XML文档中放入回车符.
这是当前的字符串输出:
We have a program that loops x number of times (based on payment #)
As it gets thru each record we would like the VB code to put a carriage return in the XML document.
Here is the current string output:
Here is what it does now:
根据付款次数,计划"部分的输出作为一个很长的字符串出现.
< paysched>
<参数>
< title></title>
< loanamount> 93456.91</loanamount>
<周期> 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>债务欠我付款</diarydesc>
< defaultdiarycode> 414</defaultdiarycode>
< schedulechange> -1</schedulechange>
</参数>
< schedule>
< record rec ="1">日期> 20101121</date><付款> 15581</payment></record>< record rec ="2">< date> 20101221 </date>付款> 15581</付款>/记录<记录rec ="3">日期20110121</date>付款" 15581</付款> </record><记录rec ="4">< date> 20110221</date><付款> 15581</payment></record>< record rec ="5"> <日期> 20110321</日期>付款15581</付款></record>"记录rec ="6"><日期> 20110421</date><付款> 15577.77 </支付></记录</计划>
< diary>
< diarydetails rec ="1">
< diarycode> 1</diarycode>
< diarydesc>已输入新的索赔</diarydesc>
</diarydetails>
< diarydetails rec ="999">
< diarycode> 999</diarycode>
< diarydesc>日记代码999-系统中的最后关闭的日记代码.</diarydesc>
</diarydetails>
</diary>
</paysched>
这是所需的输出:
< paysched>
<参数>
< title></title>
< loanamount> 93456.91</loanamount>
<周期> 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>债务欠我付款</diarydesc>
< defaultdiarycode> 414</defaultdiarycode>
< schedulechange> -1</schedulechange>
</参数>
< schedule>
< record rec ="1">< date> 20101121</date><付款> 15581</payment></record>
< record rec ="2">< date> 20101221</date><付款> 15581</payment></record>
< record rec ="3"><日期> 20110121</date><付款> 15581</payment></record>
< record rec ="4">< date> 20110221</date><付款> 15581</payment></record>
< record rec ="5">< date> 20110321</date><付款> 15581</payment></record>
< record rec ="6">< date> 20110421</date><付款> 15577.77</payment></record>
</schedule>
< diary>
< diarydetails rec ="1">
< diarycode> 1</diarycode>
< diarydesc>已输入新的索赔</diarydesc>
</diarydetails>
< diarydetails rec ="999">
< diarycode> 999</diarycode>
< diarydesc>日记代码999-系统中的最后关闭的日记代码.</diarydesc>
</diarydetails>
</diary>
</paysched>
以下是产生输出的代码:
The output for the "Schedule" section comes out as one VERY long string based on the number of payments.
<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 is producing the output:
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>" & vbCrLf
lRecCounter = lRecCounter + 1
.MoveNext
Loop
End With
Print #mlFileNum, "</schedule>"
End If
Print #mlFileNum, "</paysched>"
End Sub
推荐答案
将vbCrLf
或vbNewLine
附加到要在其上出现新行的每一行的末尾.
Append avbCrLf
orvbNewLine
to the end of each line that you want a new line to occur on.
这篇关于如何在循环时将回车符添加到xml输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!