473,394 Members | 1,640 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,394 software developers and data experts.

Modify atribute in xml file

How can I modify an attribute in a xml file?

Thank you very much
Jun 16 '06 #1
4 13247
> How can I modify an attribute in a xml file?

***
using System.Xml;

....

XmlDocument MyDoc = new XmlDocument();

try {
MyDoc.LoadXml("<root><child name=\"Change me\" /></root>");
XmlElement TempNode = MyDoc.SelectSingleNode("root//child") as XmlElement;
if (TempNode != null)
TempNode.SetAttribute("name", "new value");
MessageBox.Show(MyDoc.OuterXml);
} catch (XmlException) {
// Handle parse error here
}
***

Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jun 16 '06 #2
I forgot to mention, you can alternatively edit the attribute node directly:

***
XmlAttribute TempNode = MyDoc.SelectSingleNode("//root//child//@name") as XmlAttribute;
if (TempNode != null) TempNode.Value = "New";
***

Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jun 16 '06 #3
Thanks a lot.

"Mike D Sutton" <ED***@mvps.org> escribió en el mensaje
news:ef**************@TK2MSFTNGP05.phx.gbl...
I forgot to mention, you can alternatively edit the attribute node
directly:

***
XmlAttribute TempNode = MyDoc.SelectSingleNode("//root//child//@name") as
XmlAttribute;
if (TempNode != null) TempNode.Value = "New";
***

Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/

Jun 16 '06 #4
Mike D Sutton wrote:
XmlAttribute TempNode = MyDoc.SelectSingleNode("//root//child//@name") as


Why are you doubling your forward slashes? A forward slash is not
treated as an escape character is it?

Jun 16 '06 #5

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

Similar topics

3
by: Job Lot | last post by:
How can I modify values in text file? File is tab delimited as follows Date Buy Sell 13-Jan-2005 0.9970776 0.9901224 18-Jan-2005 0.9910566 0.9841434 I want to modify Buy and Sell...
12
by: Venkat | last post by:
Greetings to All, I have the following file and i need to modify it with the contents of an array File1.txt Name Location Points Grade Venkat,Newyork,100,A Jack,LA,12,C
2
by: Elby | last post by:
I'm looking for a the most simple and generic way to modify a file, with the possibility of making backups. In fact, I would like to emulate Perl's -i option. here is a bit of code, to explain...
4
by: jp.delatorre | last post by:
how to create script that modify xml file sample xml file: <root> <parent name="a" id="1"> <child name="a.a" id="1.1" /> <child name="a.b" id="1.2" /> <child name="a.c" id="1.3" />...
1
by: LB | last post by:
Hi, I want to modify my file ".vbproj". I use XML dlls of Visual Studio and that causes to modify the format of the file .vbproj and that causes problems at the compile time on another servor....
0
by: nkw | last post by:
My Asp.net execute a SSIS package which will modify an MDB file. It always failed. However, I can execute the SSIS package using dtexec. Should I modify the file permissions of the MDB file? If...
6
by: Joe Duchtel | last post by:
Hello - I'm trying to put together a little VB .NET (1.1 in VS 2003) application that lets me substitute the path in the Target: and Start in: fields of *.lnk files. Is there any way to do...
5
by: ziycon | last post by:
I have two PHP files, modify.php & config.php, I have the below code in config.php and I'm wondering how I would go about searching config.php from modify.php and changing the values in config.php? ...
1
by: hwee | last post by:
When a file changes (.doc or .txt file) by some user, is there away to find out who modify that file in vb.net? I know how to find the creator of the file but not the one, who modify the file.
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.