Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Deleting an XML node in C#

Deleting an XML node in C#

Scheduled Pinned Locked Moved C#
csharpxml
4 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    varsh12
    wrote on last edited by
    #1

    i want to delete a node an xml code in c# eg: just delete thanx in advance

    OriginalGriffO P S 3 Replies Last reply
    0
    • V varsh12

      i want to delete a node an xml code in c# eg: just delete thanx in advance

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      What are you using to access the XML? How are you storing it?

      Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • V varsh12

        i want to delete a node an xml code in c# eg: just delete thanx in advance

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Assuming you are retrieving this in an XmlDocument, just call DocumentElement.RemoveChild and pass in the node that you are interested in removing (you actually have to retrieve this node using something like XPath for instance).

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        1 Reply Last reply
        0
        • V varsh12

          i want to delete a node an xml code in c# eg: just delete thanx in advance

          S Offline
          S Offline
          Sir Dot Net
          wrote on last edited by
          #4

          If you're using .NET 3.5+

          XDocument doc = XDocument.Load( "file.xml" );
          var authors = ( from n in doc.Descendants( "author" )
          select n );
          if (authors != null) {
          authors.Remove();
          doc.Save( "file.xml" );
          }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups