469,290 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Change node attribute value

How would I change the value of an attribute in an XML node using C#?

I have tried "findnode.Attributes["ID"].InnerText = newValue;"
and
"Attribute attri = (XmlAttribute)findnode.Attributes["ID"].Value;"

but Im stuck! When I try casting, it say that it cannot convert a string to
an XMLAttribute or when I try setting it to a new value it says "Object
reference not set to an instance of an object."

-------XML--------
<attr-inst id="20" state="known">
<val>100</val>
</attr-inst>

Thanks for any help,
Grant
Nov 12 '05 #1
3 15227
> <attr-inst id="20" state="known">
<val>100</val>
</attr-inst>

XmlAttribute attr = findnode.Attributes["id"] should give you the
attribute (remeber XML is case sensitive).
Then attr.Value="someText" should do it.

This may help;

http://www.w3.org/TR/REC-DOM-Level-1...-one-core.html

Nov 12 '05 #2
findnode.Attributes.GetNamedItem["id"].Value = newValue;
"Grant" <gp*****@hotmail.com> wrote in message
news:ug**************@TK2MSFTNGP10.phx.gbl...
How would I change the value of an attribute in an XML node using C#?

I have tried "findnode.Attributes["ID"].InnerText = newValue;"
and
"Attribute attri = (XmlAttribute)findnode.Attributes["ID"].Value;"

but Im stuck! When I try casting, it say that it cannot convert a string
to an XMLAttribute or when I try setting it to a new value it says "Object
reference not set to an instance of an object."

-------XML--------
<attr-inst id="20" state="known">
<val>100</val>
</attr-inst>

Thanks for any help,
Grant

Nov 12 '05 #3
Tut I was so close...

Thanks for your help, and that site will be very useful too, thank you.
<ge*****************@yahoo.co.uk> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
<attr-inst id="20" state="known">
<val>100</val>
</attr-inst>

XmlAttribute attr = findnode.Attributes["id"] should give you the
attribute (remeber XML is case sensitive).
Then attr.Value="someText" should do it.

This may help;

http://www.w3.org/TR/REC-DOM-Level-1...-one-core.html

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andy Fish | last post: by
2 posts views Thread by nkunapa | last post: by
3 posts views Thread by Grant | last post: by
1 post views Thread by John Wilhelm | last post: by
4 posts views Thread by Hemal Pandya | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.