Help load XML to listbox have old value in new line

alseif

New member
Joined
Feb 14, 2012
Messages
3
Programming Experience
Beginner
Hi ! I'm load file XML to listbox It have old value in new line how to edit it.

HTML:
<?xml version="1.0"?>

<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications       with XML.</description>
  </book>
  <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-12-16</publish_date>
    <description>A former architect battles corporate zombies,       an evil sorceress, and her own childhood to become queen       of the world.</description>
  </book>
</catalog>
this code

VB.NET:
Dim xdocLogin As XDocument

        xdocLogin = XDocument.Load("c:\xml\book.xml")
        Dim stb As New StringBuilder
        For Each e As XElement In xdocLogin.Root.Elements
            stb.AppendFormat(e.@id & " " & e.<title>.Value)
            ListBox1.Items.Add(stb.ToString)
        Next
        'txt.Text = stb.ToString
     End Sub
when I complie it show result


result is mistake it get old value to show in listbox
bk101 XML Developer's Guide
bk101 XML Developer's Guide bk102 Midnight Rain
bk101 XML Developer's Guide bk102 Midnight Rain bk103 Maeve Ascendant

I want to show
bk101 XML Developer's Guide
bk102 Midnight Rain
bk103 Maeve Ascendant

thank you for help
 
Last edited by a moderator:
Remove the StringBuilder and use the Items.Add method only.

If you need support for composite string formatting (which you currently don't), use the String.Format method.
 
Back
Top