XmlDocument xmlDoc = new XmlDocument()
xmlDoc.Load(filename)
(xmlDoc.SelectSingleNode(@"//客户[@客户姓名='王五']") as XmlElement).SetAttribute("客户性别", "男")
xmlDoc.Save(filename)
不知道你是问什么东东但是如果你是想把这两个类序列化到XML文件,我这里有代码
首先在命名空间里面创建一个struct
public struct XmlElement
{
public BackUpEditionModel backUpEditionModel
public DllInfo dllInfo
}
public class Xml
{
private XmlElement xmlElement
public XmlElement XmlElementAttribute
{
get{return this.xmlElement}
set{this.xmlElement = value}
}
public bool SaveToXml(string path)
{
XmlSerializer xml = new XmlSerializer(typeof(XmlElement))
StreamWriter sw = new StreamWriter(path, false, Encoding.Default)
try
{
xml.Serialize(sw, xmlElement)
}
catch (Exception ex)
{
return false
}
finally
{
sw.Close()
}
return true
}
public bool loadFromXml(string path)
{
XmlSerializer xml = new XmlSerializer(typeof(XmlElement))
StreamReader sr = new StreamReader(path, Encoding.Default)
try
{
this.xmlElement = (XmlElement)xml.Deserialize(sr)
}
catch (Exception ex)
{
return false
}
finally
{
sr.Close()
}
return true
}
}
之后你再建立一个main方法,把你的路径进去就可以了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)