Results 1 to 3 of 3

Thread: [RESOLVED] deleting xml nodes

  1. #1

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Resolved [RESOLVED] deleting xml nodes

    I now have a similar xml problem. Now that I can create and add to the file, I only have two more problems to solve.

    1) How do I remove all nodes (without starting over from scratch, hopefully)?

    2) How can I limit the number of nodes in the xml file?

    That should do it (for now at least) until somebody wants some other feature.http://www.vbforums.com/images/smilies/smile.gif

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: deleting xml nodes

    Using the last project I gave you.

    Remove all nodes
    Code:
    Private Sub cmdRemoveAll_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles cmdRemoveAll.Click
    
        If (MessageBox.Show("Remove all nodes?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = MsgBoxResult.Yes) Then
            Dim Document As New XDocument
            Document = XDocument.Load(EntryFile)
    
            Dim Items = (From T In Document...<Entries>).FirstOrDefault
            If Items IsNot Nothing Then
                Items.RemoveAll()
                Document.Save(EntryFile)
                bsData.DataSource = New List(Of Person)
            End If
        End If
    
    End Sub
    Count all elements which you can then make an informed decision whether to allow more elements to be added or not.

    Code:
    Dim Document As New XDocument
    Document = XDocument.Load(EntryFile)
    Dim PersonCount = (From T In Document...<Entry> Select T).Count

  3. #3

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Re: deleting xml nodes

    thanks, that seems to have fixed me up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width