How to change the value of an attribute in a new XML document?



I have a database where is a ton of XML file who's waiting to get update. The update would wipe ALL files in the database. Each new file would be the same as his previous except for the attribute value.


But I want to keep each attributes type that have session as value. This attribute is in each file multiple time. But, it's doesn't work for the moment: attributes doesn't update at all).



How can I change the value of an specific attribute in an new XML file identical depending of another one?



This is what I did so far...


So I decided to find a way to get the path to these attributes using this code for each file before the wipe:



/*reader*/
XmlDocument doc = new XmlDocument();
doc.LoadXml(sessionType.Parameters);

XmlNode root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("//node()[@type='session']");
dBPathTypeSession.Add(new XmlList("b_session_type", i, nodes));//table,row,paths


And then correct the attributes value after the update with this:



XmlDocument doc = new XmlDocument();
doc.LoadXml(sessionType.Parameters);

foreach (XmlNode node in file.Paths)//XmlList file = new XmlList();
{
if (node.Attributes["type"].Value == "system")
{
node.Attributes["type"].Value = "session";
}
}
//push to DB


The informations for every path in each file is contain in this:



//But I think this is pointless for my question
public class XmlList
{
public XmlList(string tablePath, int filePath, XmlNodeList paths)
{
this.TablePath = tablePath;
this.FilePath = filePath;
this.Paths = paths;
}
public string TablePath {get; private set;}
public int FilePath {get; private set;}
public XmlNodeList Paths {get;set;}
}


I'm using C# 3.0(framework 3.5), I MUST use XMLDocument to make it fit with everything else in the code.


If you need more information just ask in comment and I will update the post.


No comments:

Post a Comment