473,508 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

modification of XML file

Hi!

I'm quite new to C#, and I want to edit an XML file. I followed the
HOW-TO here :
http://support.microsoft.com/default...b;en-us;317666 but it
didn't help that much. I work under Linux and MonoDevelop. The file I
want to modify is here : http://pastebin.com/542434
Let's say that I want to edit the "mtime" field. I use this piece of
code : http://pastebin.com/542437
Actually, I don't get any compilation error, but I don't get any
modification as well... Does somedy see an error somewhere in the code
?

Thanks in advance for your help!
Vincent.

Feb 7 '06 #1
4 2121
Hi Vincent,
a couple of points pop out:

1. You are not loading any data into the XmlDocument object, you need to add
a line like:
xmlDoc.Load(txtReader);

2. Your XPath query is not correct, instead of being "entry" it should be
"/gconf/entry"

3. You ar enot saving your changes back to file, you are only modifying
them in memory.

Below is some code that is a modified version of what you posted, it should
work for you:
XmlDocument xmlDoc = new XmlDocument();
String path = "background.xml";

xmlDoc.Load(path);
XmlNodeList nodeList = xmlDoc.SelectNodes("/gconf/entry");

foreach (XmlNode node in nodeList)
{
node.Attributes["mtime"].Value =
(Int32.Parse(node.Attributes["mtime"].Value) + 1).ToString();
}

xmlDoc.Save("background.xml");

Hope that helps
Mark Dawson
http://www.markdawson.org


"Vincent" wrote:
Hi!

I'm quite new to C#, and I want to edit an XML file. I followed the
HOW-TO here :
http://support.microsoft.com/default...b;en-us;317666 but it
didn't help that much. I work under Linux and MonoDevelop. The file I
want to modify is here : http://pastebin.com/542434
Let's say that I want to edit the "mtime" field. I use this piece of
code : http://pastebin.com/542437
Actually, I don't get any compilation error, but I don't get any
modification as well... Does somedy see an error somewhere in the code
?

Thanks in advance for your help!
Vincent.

Feb 7 '06 #2
Thank you Mark, it works perfectly well! Sorry to have wasted your
time, I'm a real beginner (and a little stupid!) as you can see ;)
Thank you again.
Vincent.

Feb 7 '06 #3
Hi Vincent,
no need to be sorry, we all were beginners at some point :-) Just keep
plugging away and in no time you will be flying through the code.

Mark.

"Vincent" wrote:
Thank you Mark, it works perfectly well! Sorry to have wasted your
time, I'm a real beginner (and a little stupid!) as you can see ;)
Thank you again.
Vincent.

Feb 7 '06 #4
Hi again,

What if I want to modify the values between the "stringvalues" tags ? I
tried to do with the help of the nodeList, but it seems that it's not
the good way to do it... BTW, maybe you know a good c#/xml tutorial
that i can use insted of bothering you ;)

Thanks for your help!

Feb 8 '06 #5

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

Similar topics

3
1253
by: nathan_kent_bullock | last post by:
Assume I am using a class Foo. I want to find out the modification time of the file that that class was defined in. How would I go about this? If I could find out the name of the file that Foo...
2
2284
by: janek | last post by:
My question How can I do something like this... in Builder: In ListBox I've got a list of the files (load by the FindDir) and what should I do to pull out from these files the size and the time...
3
2009
by: stan | last post by:
I am working on some documentation in html format and I would really like to display the date the html file, itself was modified. I am writing my documentation in vi and the html server involved is...
9
2929
by: Jay Kim | last post by:
Hi, We're implementing a Windows application using Visual Basic .NET. One of the key features we need to implement is that we should be able to get the accurate byte offset of user selected...
10
1474
by: sandorf | last post by:
I'm using the Windows version of Python and IDLE. When I debug my .py file, my modification to the .py file does not seem to take effect unless I restart IDLE. Saving the file and re-importing it...
1
1750
by: Henry Law | last post by:
(I posted this to comp.infosystems.www.browsers.misc but there seems to be very little traffic there. I can't see another suitable group; is it on topic here? If not, any suggestions as to...
13
1793
by: ts-dev | last post by:
Is it possible to prevent modification of a python file once its been deployed? File permissions of the OS could be used..but that doesn't seem very secure. The root of my question is verifying...
2
1908
by: Unpopular | last post by:
void directory::modification()//??????????? { clrscr(); cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ "; cout<< "\n\t=====@ @ @ @ @ @ @@...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.