473,382 Members | 1,375 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,382 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 12 '05 #1
3 15436
> <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 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...
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...
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;" ...
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>...
1
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.