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. Change an XML attribute using C#

Change an XML attribute using C#

Scheduled Pinned Locked Moved C#
csharpxmlhelptutorial
3 Posts 2 Posters 0 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.
  • N Offline
    N Offline
    nyjcr
    wrote on last edited by
    #1

    Hello all, I'm trying to change an attribute in an XML document based on some criteria, I'm using C#, For example I need to do a "search" based on a person's user id, the user id is an attribute of a node name student. if the userid matches a text box I then need to change the Grade attribute of the student. for example, my xml document looks like this I want to 'search' for student 345 and then change the Grade to an 'A' Any help would be greatly appreciated. JC

    C 1 Reply Last reply
    0
    • N nyjcr

      Hello all, I'm trying to change an attribute in an XML document based on some criteria, I'm using C#, For example I need to do a "search" based on a person's user id, the user id is an attribute of a node name student. if the userid matches a text box I then need to change the Grade attribute of the student. for example, my xml document looks like this I want to 'search' for student 345 and then change the Grade to an 'A' Any help would be greatly appreciated. JC

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can select a node in an XmlDocument using Xpath and then use the Attributes collection to access/change an attribute.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      N 1 Reply Last reply
      0
      • C Christian Graus

        You can select a node in an XmlDocument using Xpath and then use the Attributes collection to access/change an attribute.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        N Offline
        N Offline
        nyjcr
        wrote on last edited by
        #3

        Thank you for your help.. How I got it to work. created a new element, assigned the old node to a new node specific to my search criteria

        newnode = root.SelectSingleNode("Students/Student/[@userid='" + loginform.userid + "']");

        I then created a new attribute and used the append function to add the newly created attribute as the last attribute. saved the document... and it worked.. hope this help someone.... thanks again. JC

        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