Reputation: 884
I am writing data from a vb project to an XML document. When I recall the data, all the previous notes are coming back as one long line of text. How can I break the lines by submission to the XMl document?
Code:
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
Code that retrieves the elements from 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
Upvotes: 1
Views: 2890
Reputation: 54532
I am presumming that you are using a TextBox, its Multiline property is set to True and the character you are using for the NewLine is part of the string being input from the xml file, You can try using String.Replace or if you need to split into seperate Strings you can use String.Split
txtPastNote.Text = element.note.Replace("\n", vbCrLf)
Upvotes: 1