473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 16 '05 #1
3 1866
> <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 16 '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 16 '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 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
3
by: Andy Fish | last post by:
Hi, I just found this template in someone else's xslt (it's Microsoft's "word2html" stylesheet to convert WordProcessingML to HTML) <xsl:template match="WX:sect"> <xsl:variable...
2
by: nkunapa | last post by:
Hi: Is there a way in XPATH to find the nearest node of the node in context with a certain attribute value. Here is my problem. I have the following XML and I am trying to add all the nodes with...
3
by: Grant | last post by:
How would I change the value of an attribute in an XML node using C#? I have tried "findnode.Attributes.InnerText = newValue;" and "Attribute attri = (XmlAttribute)findnode.Attributes.Value;" ...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
2
by: Rick | last post by:
I have an XML document that is generated from Infopath, I need to change the value of a namespace that is defined in a node in the form: <xsf:xDocumentClass "xmlns:my=valuehere">. when i navigate...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
8
by: patrizio.trinchini | last post by:
Hi All, I'would like to write an XSL transformation that changes the value of the atribute of a given element according to the value of another atttribute of the same element. For instance,...
4
by: Hemal Pandya | last post by:
Hello, I am hoping this is a simple question with a straightforward solution. I do not understand xsl much, so I apologize in advance if I am asking a stupid question. Is it possible to write...
1
by: SWETA123 | last post by:
I will very helpful to you if you can help me out in my below problem. I am not getting idea what should be the right approach for this. Here is my problem. I have below (sample)xml. <Rules>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.