使用从VB.Net到XML的换行符

时间:2012-04-19 23:56:55

标签: xml vb.net vb.net-2010

我正在将数据从vb项目写入XML文档。当我回想起这些数据时,所有以前的笔记都会以一长串文本的形式返回。如何通过提交到XMl文档来划分界限?

代码:

Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles     btnSave.Click

        Dim AcctNum = txtAcctNum.Text.ToString

        'Dim note1 As String = ""

        'Dim linebreak As String = "<br />"

        'Str & VBNewLine
        'Str & VBCrLf

        Dim note2 As String = TxtNotes.Text
        'note2(0) = vbNewLine
        'note2(1) = TxtNotes.Text()

        Dim note3 As String = txtPastNote.Text

        note2 = note3 + "\n" + note2

        Dim root As XElement = XElement.Load("CreditApp.xml")

        Dim customer = From el In root.<custData>
                       Where el.<AcctNum>.Value = AcctNum
                       Select el

        For Each element In customer
            element.SetElementValue("Note", note2)
        Next

        'Dim NewNote As String = note1 + note2

        'Dim doc As New XmlDocument
        'doc.Load("CreditApp.xml")

        'Dim custData As XmlElement = doc.CreateElement("custData")

        'Dim note As XmlElement = doc.CreateElement("Note")
        'note.InnerText = NewNote

        'custData.AppendChild(note)
        'doc.DocumentElement.AppendChild(custData)

        root.Save("CreditApp.xml")
        MessageBox.Show("NOTES SAVE")

    End Sub

从XML中检索元素的代码:

 For Each element In customer
            txtSSN.Text = element.ssn
            txtfName.Text = element.fname
            txtlName.Text = element.lname
            txtAcctNum.Text = element.acctnum
            txtVerfiWord.Text = element.passcode
            txtAcctAmt.Text = element.acctAval
            txtAcctBal.Text = element.acctbal
            txtLPmtAmt.Text = element.lpmtamt
            txtLPmtDate.Text = element.lpmtdate
            txtGender.Text = element.gender
            txtAddress.Text = element.address
            txtCity.Text = element.city
            txtState.Text = element.state
            txtZip.Text = element.zip
            txtPhone.Text = element.phone
            txtEmail.Text = element.email
            txtCreditLmt.Text = element.creditlim
            txtIntRate.Text = element.intrate
            txtMinPmtDue.Text = element.minpay
            txtPmtDueDate.Text = element.pmtduedate
            txtPastNote.Text = element.note

end sub

1 个答案:

答案 0 :(得分:1)

我假设您正在使用TextBox,其Multiline属性设置为True,而您用于NewLine的字符是从xml文件输入的字符串的一部分,您可以尝试使用String.Replace或者如果您需要拆分成单独的字符串,可以使用String.Split

txtPastNote.Text = element.note.Replace("\n", vbCrLf)