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

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 2116
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
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
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
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
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
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
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
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
by: Unpopular | last post by:
void directory::modification()//??????????? { clrscr(); cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ "; cout<< "\n\t=====@ @ @ @ @ @ @@...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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.