string xmlpath = Application.StartupPath; try { if(File.Exis
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/16 13:58:52
string xmlpath = Application.StartupPath; try { if(File.Exists(xmlpath+@"\"+"StoreHistory.xml")) {
string xmlpath = Application.StartupPath;
try
{
if(File.Exists(xmlpath+@"\"+"StoreHistory.xml"))
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlpath + @"\" + "StoreHistory.xml");
XmlElement xe = doc.DocumentElement;
XmlElement newhistory=doc.CreateElement("history");
XmlElement newtime=doc.CreateElement("time");
XmlElement newtitle=doc.CreateElement("title");
XmlElement newweb = doc.CreateElement("web");
XmlText time = doc.CreateTextNode(Time);
XmlText title = doc.CreateTextNode(Title);
XmlText web = doc.CreateTextNode(Website);
newhistory.AppendChild(newtime);
newhistory.AppendChild(newtitle);
newhistory.AppendChild(newweb);
newtime.AppendChild(time);
newtitle.AppendChild(title);
newweb.AppendChild(web); xe.InsertAfter(newhistory,xe.LastChild);
doc.Save(xmlpath + @"\" + "StoreHistory.xml");
}
保存网页的历史记录代码 3Q
{
XmlWriter xwr = null;
try
{
XmlWriterSettings
settings = new XmlWriterSettings();
settings.Indent =
true;
settings.IndentChars
= (" ");
xwr =
XmlWriter.Create("StoreHistory.xml",settings);
xwr.WriteStartElement("Root");
xwr.WriteStartElement("history");
xwr.WriteStartElement("time");
xwr.WriteValue(Time);
xwr.WriteEndElement(); xwr.WriteStartElement("title");
xwr.WriteValue(Title);
xwr.WriteEndElement();
xwr.WriteStartElement("web"); xwr.WriteValue(Website);
xwr.WriteEndElement();
xwr.WriteEndElement();
xwr.WriteEndElement();
}解释得很清楚 这段是接着上一段的假如不存在那个xml文件
string xmlpath = Application.StartupPath;
try
{
if(File.Exists(xmlpath+@"\"+"StoreHistory.xml"))
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlpath + @"\" + "StoreHistory.xml");
XmlElement xe = doc.DocumentElement;
XmlElement newhistory=doc.CreateElement("history");
XmlElement newtime=doc.CreateElement("time");
XmlElement newtitle=doc.CreateElement("title");
XmlElement newweb = doc.CreateElement("web");
XmlText time = doc.CreateTextNode(Time);
XmlText title = doc.CreateTextNode(Title);
XmlText web = doc.CreateTextNode(Website);
newhistory.AppendChild(newtime);
newhistory.AppendChild(newtitle);
newhistory.AppendChild(newweb);
newtime.AppendChild(time);
newtitle.AppendChild(title);
newweb.AppendChild(web); xe.InsertAfter(newhistory,xe.LastChild);
doc.Save(xmlpath + @"\" + "StoreHistory.xml");
}
保存网页的历史记录代码 3Q
{
XmlWriter xwr = null;
try
{
XmlWriterSettings
settings = new XmlWriterSettings();
settings.Indent =
true;
settings.IndentChars
= (" ");
xwr =
XmlWriter.Create("StoreHistory.xml",settings);
xwr.WriteStartElement("Root");
xwr.WriteStartElement("history");
xwr.WriteStartElement("time");
xwr.WriteValue(Time);
xwr.WriteEndElement(); xwr.WriteStartElement("title");
xwr.WriteValue(Title);
xwr.WriteEndElement();
xwr.WriteStartElement("web"); xwr.WriteValue(Website);
xwr.WriteEndElement();
xwr.WriteEndElement();
xwr.WriteEndElement();
}解释得很清楚 这段是接着上一段的假如不存在那个xml文件
功能:读取xml文件并修改(加入一些节点).
Application.StartupPath --》bin文件夹的路径
file.exist(文件路径)--》判断文件是否存在.
XmlDocument.CreateElement 创建元素
XmlDocument doc = new XmlDocument();//新建一空xml对象,
XmlElement xe = doc.DocumentElement;//赋值(从源文件),
XmlElement newhistory=doc.CreateElement("history"); //新建元素(节点)
newhistory.AppendChild(newtime); //添加子元素(节点)
newhistory.AppendChild(newweb); //添加子元素(节点)
xe.InsertAfter(newhistory,xe.LastChild); //在末尾插入此节点
————————————————————
以上代码在xml中添加一个history元素,结果如下:
----》XmlElement newhistory=doc.CreateElement("history");
--》newhistory.AppendChild(newtime);
————————————
补充问题:
------>>xwr.WriteStartElement("Root");
----->>xwr.WriteStartElement("history");
--->>xwr.WriteStartElement("time");
Time 的值 --->>xwr.WriteStartElement("time");
--->>xwr.WriteEndElement();
Title的值 ...
Web的值 ...
-->>xwr.WriteEndElement();
-->>xwr.WriteEndElement();
-------
XmlWriterSettings
settings = new XmlWriterSettings();
settings.Indent =true; ----->>允许缩进
settings.IndentChars = (" "); ---》缩进字符为空格
天.你后面不会还有吧?
Application.StartupPath --》bin文件夹的路径
file.exist(文件路径)--》判断文件是否存在.
XmlDocument.CreateElement 创建元素
XmlDocument doc = new XmlDocument();//新建一空xml对象,
XmlElement xe = doc.DocumentElement;//赋值(从源文件),
XmlElement newhistory=doc.CreateElement("history"); //新建元素(节点)
newhistory.AppendChild(newtime); //添加子元素(节点)
newhistory.AppendChild(newweb); //添加子元素(节点)
xe.InsertAfter(newhistory,xe.LastChild); //在末尾插入此节点
————————————————————
以上代码在xml中添加一个history元素,结果如下:
----》XmlElement newhistory=doc.CreateElement("history");
--》newhistory.AppendChild(newtime);
————————————
补充问题:
------>>xwr.WriteStartElement("Root");
----->>xwr.WriteStartElement("history");
--->>xwr.WriteStartElement("time");
Time 的值 --->>xwr.WriteStartElement("time");
--->>xwr.WriteEndElement();
Title的值 ...
Web的值 ...
-->>xwr.WriteEndElement();
-->>xwr.WriteEndElement();
-------
XmlWriterSettings
settings = new XmlWriterSettings();
settings.Indent =true; ----->>允许缩进
settings.IndentChars = (" "); ---》缩进字符为空格
天.你后面不会还有吧?
string xmlpath = Application.StartupPath; try { if(File.Exis
Application.StartupPath.Substring(0,Application.StartupPath.
c# public static bool IsSelectNode(string xmlPath,string nod
String scheme ,scheme.("file")是什么意思?
This file is either temporarily unavailable or does not exis
Application Initial File Error,reinstall the application App
your application was not able to find a license file
this application has encountered a critical error.the file d
if(field.getType() == String.class){ } 为什么必须要有这句?
class C { public static void test(String s) { if(s == null |
if (string.IsNullOrEmpty(Request["DropDownList1"])) return;
String str2 = "";