What is going wrong with this simple CODE "loading names into a listbox"

Posted on 2011-10-10
Last Modified: 2012-05-12
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim doc = XDocument.Load(myPath)
        For Each item In doc...<Contact>
            lstMem.Items.Add(item.@Fname & " " & item.@Lname)

    End Sub

This opens a simple XML parses it and returns the names in the listbox
However no matter if I close the app and reopen it .... I get a space in the listbox like this

It should return this
John Doe
Jane Doe
Jim Smith
Jene Smith
Sally Somebody

BUT I get this
John Doe
                <------ Note the empty space
Jane Doe
Jim Smith
Jene Smith
Sally Somebody

Now one thing you might should know I had another name but deleted it using this code
Dim doc = XDocument.Load(myPath)

        Dim remCon = From rC In doc.<AddBook>.<Contact> _
                     Where rC.@Fname = txtfName.Text _
                     Where rC.@Lname = txtLname.Text _
                     Select rC

        For Each itm In remCon


I closed the app re opened it and I get the space like it is remembering where the record was I deleted ... its crazy ...
I check the xml file ... the node and its children are gone as they should be ... I even re saved the xml file and it still does it when I open the app

This is totally got me stumped here guys
Question by:vbMarkO

    Author Comment

    Arrrrrgh I think I found it
    In the XML file when it deletes the Node and its children its not getting everything it leaves this

      <Contact />
    So its reading that when it loads .. so the question is why isnt my code deleting everything then????
    LVL 7

    Accepted Solution

    I think when you call itm.RemoveAll(), it is saying "remove all the inner contents of this node".  

    I am guessing that what you want is itm.Remove(), for which the documentation reads: "Removes this node from its parent."

    Check this link for more details:

    Best of Luck.

    Author Closing Comment

    Yep that did it ... thanx a million

    I so appreciate it!!!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now