生成xml与获取xml
来源:互联网 发布:家具摆放软件 编辑:程序博客网 时间:2024/05/17 22:48
private string fileName = "adphoto.xml";
/// <summary>
/// 插入XML
/// </summary>
/// <param name="id"></param>
/// <param name="imageName"></param>
/// <param name="fileName"></param>
public void AddImg(string id, string imageName, string fileName)
{
fileName = "~/xml/" + fileName;
var sPath = Server.MapPath(fileName);
XmlDocument doc = new XmlDocument();
doc.Load(sPath);
XmlNode root = doc.SelectSingleNode("resultxml");//查找<resultxml>
XmlElement xe1 = doc.CreateElement("item");
xe1.SetAttribute("id", id);
xe1.SetAttribute("thumb", imageName);
root.AppendChild(xe1);
doc.Save(sPath);
}
/// <summary>
/// 更新
/// </summary>
/// <param name="keyName"></param>
/// <param name="upimgName"></param>
/// <param name="fileName"></param>
public void UpdateImg(string keyName, string upimgName, string fileName)
{
fileName = "~/xml/" + fileName;
var sPath = Server.MapPath(fileName);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(sPath);
XmlNodeList elemList = xmlDoc.GetElementsByTagName("item");
foreach (XmlNode list in elemList)
{
XmlElement element = list as XmlElement;
string str = element.GetAttribute("thumb");
if (str == keyName)
{
element.SetAttribute("thumb", upimgName);
element.SetAttribute("id", keyName);
}
}
XmlTextWriter xw = new XmlTextWriter(new StreamWriter(sPath));
xw.Formatting = Formatting.Indented;
xmlDoc.WriteTo(xw);
xw.Close();
}
/// <summary>
/// 删除
/// </summary>
/// <param name="keyName"></param>
/// <param name="fileName"></param>
public void DelImg(string keyName, string fileName)
{
// fileName = "photo_list.xml";
// keyName = "9a.jpg";
fileName = "~/xml/" + fileName;
var sPath = Server.MapPath(fileName);
XmlDocument doc = new XmlDocument();
doc.Load(sPath);
XmlNodeList xnl = doc.SelectSingleNode("resultxml").ChildNodes;
foreach (XmlNode xn in xnl)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("thumb") == keyName)
{
doc.SelectSingleNode("resultxml").RemoveChild(xe);
}
}
doc.Save(sPath);
}
- 生成xml与获取xml
- 生成xml与获取xml
- 读取与生成XML
- XML生成与解析
- xml 生成与解析
- xml解析与xml的生成
- Java解析XML与生成XML文件
- XML的解析与生成
- xml的生成与解析
- C#XML生成与解析
- XML的解析与生成
- android xml解析与生成
- xml解析生成与解析
- jaxb xml生成与解析
- XML的解析与生成
- XML的生成与解析
- Python 生成与解析 XML
- XML的解析与生成
- 黑马程序员—.NET基础—01
- 大端模式和小端模式
- 使用python中的urlretrieve下批量下载数据
- Window XP驱动开发(十七) 芯片固件程序设计 (代码实现,针对USB2.0 芯片CY7C68013A)
- 基于微软Dryad分布式并行计算平台云技术的研究
- 生成xml与获取xml
- MongoDB数据库(一)
- Android 软件自动更新 (网络XML解析、以及本地xml软件版本两种解析方式)
- 四元数
- linux 库的编译方法
- 【学习点滴-数据结构-栈&队列】 用两个栈模拟一个队列
- 一步一步走进块驱动之第二章
- Mongodb VS Hbase
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor