现在要实现的功能就是如<Employees>
<Node name="dd" gangwei="dd" time="2011/4/27 9:43:34" />
</Employees>这样的,当我C#后台重新调用函数的时候,应该生成
<Employees>
<Node name="dd" gangwei="dd" time="2011/4/27 9:43:34" />
<Node name="dd" gangwei="dd" time="2011/4/27 9:43:34" />
</Employees>这样的效果,而不是把第一个节点Node给替换掉,求教各位高手,该怎么实现呢?
后台代码贴出,望指教,在线等。
protected void AddXml()
{
xmldoc = new XmlDocument();
//加入XML的声明段落<?xml version="1.0" encoding="gb2312"?>
XmlDeclaration xmldecl;
xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
xmldoc.AppendChild(xmldecl);
//加入一个根元素
xmlelem = xmldoc.CreateElement("", "Employees", "");
xmldoc.AppendChild(xmlelem);
//加入另外一个元素 XmlNode root = xmldoc.SelectSingleNode("Employees");//查找<Employees>
XmlElement xe1 = xmldoc.CreateElement("Node");//创建一个<Node>
xe1.SetAttribute("name", Request["textname"] + "");//设置该节点属性
xe1.SetAttribute("gangwei", Request["textfirst"] + "");//设置该节点属性
xe1.SetAttribute("time",DateTime.Now+"");
root.AppendChild(xe1);//添加到<Employees>节点中
//保存创建好的XML文档
xmldoc.Save(Server.MapPath("Recruitment.xml"));
}
<Node name="dd" gangwei="dd" time="2011/4/27 9:43:34" />
</Employees>这样的,当我C#后台重新调用函数的时候,应该生成
<Employees>
<Node name="dd" gangwei="dd" time="2011/4/27 9:43:34" />
<Node name="dd" gangwei="dd" time="2011/4/27 9:43:34" />
</Employees>这样的效果,而不是把第一个节点Node给替换掉,求教各位高手,该怎么实现呢?
后台代码贴出,望指教,在线等。
protected void AddXml()
{
xmldoc = new XmlDocument();
//加入XML的声明段落<?xml version="1.0" encoding="gb2312"?>
XmlDeclaration xmldecl;
xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
xmldoc.AppendChild(xmldecl);
//加入一个根元素
xmlelem = xmldoc.CreateElement("", "Employees", "");
xmldoc.AppendChild(xmlelem);
//加入另外一个元素 XmlNode root = xmldoc.SelectSingleNode("Employees");//查找<Employees>
XmlElement xe1 = xmldoc.CreateElement("Node");//创建一个<Node>
xe1.SetAttribute("name", Request["textname"] + "");//设置该节点属性
xe1.SetAttribute("gangwei", Request["textfirst"] + "");//设置该节点属性
xe1.SetAttribute("time",DateTime.Now+"");
root.AppendChild(xe1);//添加到<Employees>节点中
//保存创建好的XML文档
xmldoc.Save(Server.MapPath("Recruitment.xml"));
}
解决方案 »
- 【40分求助】奇怪的问题,抽象类以及Expression类
- 请问可不可一用同一个Socket联系收发消息啊?急!
- 如何屏蔽AxWebBrowser弹出的脚本错误
- 救急,读配置文件,~~~
- 配置文件的加密解密问题
- hook textout的时候,为什么取到的文本是一个字一个字的呢?
- 从数据库中得到的数据如何转化为xml文件?
- IBM Rational Software Modeler + Rational Modeling Extension for Microsoft .NET,是否等于XDE for VS.NET2003?
- vs2005数据库访问
- 请教:如何获取出错位置的方法、函数名称?如何获取出错位置的代码行位置?如何获取当前类名称?
- 窗体上显示表格
- socket 多线程 文件传输
if (File.Exists(Server.MapPath("Recruitment.xml")))
{
xmldoc.Load(Server.MapPath("Recruitment.xml"));
}
else
{
xmldoc = new XmlDocument();
//加入XML的声明段落<?xml version="1.0" encoding="gb2312"?>
XmlDeclaration xmldecl;
xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
xmldoc.AppendChild(xmldecl); }这样,前面先去判断是否存在该文件了。
XmlDocument xmldoc = new XmlDocument();
//加入XML的声明段落,<?xml version="1.0" encoding="gb2312"?>
XmlDeclaration xmldecl;
xmldecl = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
xmldoc.AppendChild(xmldecl);
XmlElement rootElement = null;
XmlElement parentElement = null;
XmlNode rootNode = null;
rootElement = xmldoc.CreateElement("Employees", "gb2312", "");
xmldoc.AppendChild(rootElement);
rootNode = xmldoc.SelectSingleNode("Employees");
parentElement = xmldoc.CreateElement("Node");
parentElement.SetAttribute("name", "dd");
parentElement.SetAttribute("gangwei", "dd");
rootNode.AppendChild(parentElement);
xmldoc.Save("Recruitment.xml");
本内容使用CSDN小秘书回复
每天回帖即可得10分可用分!
*****************************************[/align]