Hi guys!
I am currently writing a small project and I have to deal with xml file. The file has got following structure: -
<project>
-
<configurations>
-
<configuration description>
-
<graph>
-
<filter id ="xx" alias="Twin">
-
<settings>
-
-
<property value="C:\temp" name="Temp Folder"/>
-
-
</settings>
-
</filter>
-
</graph>
-
</configuration description>
-
</configurations>
-
</project>
-
And though I tried every trick known to me ( & Dr. Google) i do not know how to read, delete and write the value of:
<property value="C:\temp" name="Temp Folder"/>
simply I want to change the "C:\temp" to smth else...
I would be glad If somebody would help with this...
Kapik
I would keep things object oriented by deserializing and editing an object and then serializing the results. -
public static void SerializeToXml<T>(T obj, string fileName)
-
{
-
XmlSerializer ser = new XmlSerializer(typeof(T));
-
ser.Serialize(fileStream, obj);
-
fileStream.Close();
-
FileStream fileStream = new FileStream(fileName, FileMode.Create);
-
}
-
public static T DeserializeFromXml<T>(string xml)
-
{
-
T result;
-
XmlSerializer ser = new XmlSerializer(typeof(T));
-
using (TextReader tr = new StringReader(xml))
-
{
-
result = (T)ser.Deserialize(tr);
-
}
-
return result;
-
}
-
4 1817
I don't know how you're reading in your XML but I suggest using an XmlDocument object. This stores a hierarchy of XmlNode objects. These have an Attributes property that provides a list of XmlAttribute objects.
Whew, lots of linking!
Anyway, you can use the Name and Value properties of an XmlAttribute object to do what you need. You'll need to follow the hierarchy down until you find the property node, then look for an attribute with the Name of "Value". You'll then want to change the value of the Value property to whatever you want. After that, you can simply get an XML string from your XmlDocument object and overwrite the file with the new XML source.
Let me know if you have any questions/troubles with the implementation :)
Thanx for the Tip Gary :)
I'll keep in touch, because currently I am able to get values out of one level only... I have tried setting the: -
XmlNodeList nodeList = xmlFile.SelectNodes("/project/configurations/configuration/graph/filter/settings");
-
as constant ones, but somehow it still doesn't work
Linking might be a veerryy good Idea.
THX, once more! :))
I would keep things object oriented by deserializing and editing an object and then serializing the results. -
public static void SerializeToXml<T>(T obj, string fileName)
-
{
-
XmlSerializer ser = new XmlSerializer(typeof(T));
-
ser.Serialize(fileStream, obj);
-
fileStream.Close();
-
FileStream fileStream = new FileStream(fileName, FileMode.Create);
-
}
-
public static T DeserializeFromXml<T>(string xml)
-
{
-
T result;
-
XmlSerializer ser = new XmlSerializer(typeof(T));
-
using (TextReader tr = new StringReader(xml))
-
{
-
result = (T)ser.Deserialize(tr);
-
}
-
return result;
-
}
-
- MySettings.Default.Reload();
-
string str = MySettings.Default.SaveClick_ModifReponse;
-
-
XmlDocument xmlDoc = new XmlDocument();
-
string path = ConfigurationManager.AppSettings["path"];
-
XmlNodeList girlReponse = xmlDoc.GetElementsByTagName("Reponse");
-
XmlNodeList girlLib = xmlDoc.GetElementsByTagName("Libelle_Reponse");
-
-
xmlDoc.Load(path);
-
-
for (int j = 0; j < girlReponse.Count; j++)
-
{
-
-
if (girlReponse[j].Attributes["Id_Reponse"].Value =="1353")
-
{
-
girlLib[j].InnerText = _libelle_reponse ;
-
xmlDoc.Save(path);
-
MessageBox.Show("les nouvelles informations sont Modifier dans le fichier xml .");
Sign in to post your reply or Sign up for a free account.
Similar topics
by: martin |
last post by:
I needed a way to display calculated, multiple, changing values
(numerical sums) as users interacted with the page, and do this
without going back to the server to load the page again.
What I...
|
by: spmm_pls |
last post by:
Hi,
Could some1 please tell me what the best way is to adjust the value of
a column in my databound datagrid (in ASP.NET)
For example my database returns the values 1,2 and 3 in the column...
|
by: Peter Rilling |
last post by:
Okay, I have a structure where I want to initialize the fields to some
special value, but I cannot initialize them directly (e.g. private bool
myBool = false) and I cannot create a defauld...
|
by: Polska, Ursula |
last post by:
Hello experts, could explain to initialize a structure?
Private Structure sEG
Public EN As Integer = 1
Public EG1 As Integer = 2
Public EG9 As String = "EG, 14.2"
End Structure
Please no...
|
by: Dave |
last post by:
Hi all,
I have a listbox that is complex bound by an arraylist. The problem is that
when I delete an object from the arraylist, the listbox does not reflect
those changes. I tried refreshing...
|
by: Anthony Liu |
last post by:
I am talking about the 'take' method of numarray.
See here for more info:
http://stsdas.stsci.edu/numarray/Doc/node33.html
If I initialize a matrix 'mymatrix' by zeros((3,3),...
|
by: mmcquade.forums |
last post by:
I've built a CROSSTAB query that will list attendance for classes.
Since the ATTENDANCE table tracks if someone was ABSENT with a yes/no
field, the results of the crosstab show "-1" if checked.
...
|
by: sbaird |
last post by:
Aloha from Hawaii,
I'm beating my head on the wall here. I have a recruiting contact
managment database I'm trying to create. Managers (there ar 14 of
them) have to make a certain number of...
|
by: nagar |
last post by:
My application connects to a SQLite db and gets a number of fields
which are displayed in a list though a typed dataset.
I need to manually update an unbound column (which contains the index
of...
|
by: yogi_bear_79 |
last post by:
I am a beginner. I am supposed to use a switch structure. I wrote
the code below, which works great, but I can't come up with a
reasonable usage of the switch structure for this program. Any...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
| |