求教这段xml怎么读出?
<?xml version="1.0"?>
<!--系统参数-->
<SystemOptions BackGroundPicturePath="" SystemLogPath="" DataBaseAutoBackupPath="" SQLSpyMode="0" AutoLoginID="0000" AutoLoginPWD="FkIz794DEXeNCp+BR/tSHDyJOVDIFLa+bs2Z/mCx2/E=" AutoRun="0" />
------------------
写入是用
string configpath = Application.StartupPath + "\\SysConfiguration.config";
XmlTextWriter xfw = new XmlTextWriter(configpath, null);
xfw.Formatting = Formatting.Indented;
xfw.WriteStartDocument();
xfw.WriteComment("系统参数");
xfw.WriteStartElement("SystemOptions");
xfw.WriteAttributeString("BackGroundPicturePath", tboxbk.Text);
xfw.WriteAttributeString("SystemLogPath", tboxlogpath.Text);
xfw.WriteAttributeString("DataBaseAutoBackupPath", tboxautobkpath.Text);
xfw.WriteAttributeString("SQLSpyMode", cbbsqlspy.SelectedIndex.ToString());
xfw.WriteAttributeString("AutoLoginID", tboxautologinid.Text);
xfw.WriteAttributeString("AutoLoginPWD", AutoLoginPWD);
if(cbbautorun.Checked == true)
xfw.WriteAttributeString("AutoRun", "1");
else
xfw.WriteAttributeString("AutoRun", "0");
xfw.WriteEndElement();
xfw.WriteEndDocument();
xfw.Flush();
xfw.Close();
--------------------------------------------------
怎么再读出呢,搞了半天没整出来。
[解决办法]
<?xml version="1.0"?>
<!--系统参数-->
<SystemOptions BackGroundPicturePath="" SystemLogPath="" DataBaseAutoBackupPath="" SQLSpyMode="0" AutoLoginID="0000" AutoLoginPWD="FkIz794DEXeNCp+BR/tSHDyJOVDIFLa+bs2Z/mCx2/E=" AutoRun="0" />
读的话可以用文件读,也可以load后XML读
XML读的话
XmlDocument doc=new XmlDocument();
Assembly exe = typeof(DownLoadMonitor).Assembly;
string pathFile = Path.GetDirectoryName(exe.Location)+"\\"+FileName;//获取XML配置文件路径
doc.Load(pathFile);//加载XML文件
//获取XML文件的相应配置字段
doc.DocumentElement["SystemOptions"].Attributes["BackGroundPicturePath"].Value
doc.DocumentElement["SystemOptions"].Attributes["SystemLogPath"].Value
[解决办法]
//string xmlString ="<PhoneBook >"+
//"<Name>加菲尔德</Name>"+
//"<Number>5556666</Number>"+
//"<City>纽约</City>"+
//"<DateOfBirth>26/10/1978</DateOfBirth>"+
//"<Name>迈克</Name>"+
//"<Number>66667777</Number>"+
//"<City>纽约</City>"+
//"<DateOfBirth>12/02/1978</DateOfBirth>"+
//"</PhoneBook>";
//
//phone.LoadXml(xmlString);
//LabelString.Text=phone.InnerText.ToString();
//添加的元素 会放到节点的末尾
//为什么没有 对 phone.xml 文件 作出相应的 修改呢 ?
//XmlDocument my=new XmlDocument();
//my.Load(@"E:\十三少\Load\phone.xml");
////获取 文档的根元素
//XmlNode root=my.DocumentElement;
//XmlElement element=my.CreateElement("Mobile");
//element.InnerText="1390102231";
//
//root.AppendChild (element);
//LabelAdd.Text=my.InnerText.ToString();
//
//XmlDocument myAttribute=new XmlDocument();
//myAttribute.Load(@"E:\十三少\Load\phone.xml");
//XmlNode ro=myAttribute.DocumentElement;
//XmlAttribute attribute=myAttribute.CreateAttribute("Mobile");
//attribute.InnerText="13800138000";
//ro.Attributes.Append(attribute);
XmlDocument myDelete=new XmlDocument();
myDelete.Load(@"E:\十三少\Load\phone.xml");
XmlNode node=myDelete.DocumentElement;
node.RemoveChild(node.ChildNodes[0]);
LabelAttribute.Text=myDelete.InnerText.ToString();
[解决办法]
如果2 个 页面,一个写,一个读, 试一试