PC Review


Reply
Thread Tools Rate Thread

Change node attribute value

 
 
Grant
Guest
Posts: n/a
 
      18th Mar 2005
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


 
Reply With Quote
 
 
 
 
geoffblanduk_nospam@yahoo.co.uk
Guest
Posts: n/a
 
      18th Mar 2005
> <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

 
Reply With Quote
 
Stephany Young
Guest
Posts: n/a
 
      18th Mar 2005
findnode.Attributes.GetNamedItem["id"].Value = newValue;


"Grant" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Grant
Guest
Posts: n/a
 
      18th Mar 2005
Tut I was so close...

Thanks for your help, and that site will be very useful too, thank you.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> <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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why XmlNode.Name get node name and its first attribute together? =?Utf-8?B?ZGF2aWQ=?= Microsoft ASP .NET 0 12th Mar 2007 05:06 PM
matching on part of node's attribute =?Utf-8?B?Sm9l?= Microsoft ASP .NET 2 3rd Feb 2006 03:35 PM
retrieving an attribute from a node in a nodelist =?Utf-8?B?bWVsYW5pZWFi?= Microsoft C# .NET 3 17th Aug 2005 04:32 PM
XPath to get a node with a certain attribute value =?Utf-8?B?Sm9u?= Microsoft Dot NET Framework 3 19th Feb 2004 02:00 AM
Adding a XML Attribute for an Exiting Node Peter Microsoft Dot NET 1 9th Dec 2003 07:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:49 PM.