日期:2014-05-18  浏览次数:20750 次

求教这段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
------解决方案--------------------
探讨
<?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 = P…

------解决方案--------------------
//----------演示使用 Load 方法 加载xml 文档
//xml 文档 用于执行 任务 .如加载和保存 xml文档.
// XmlDocument MyPhone=new XmlDocument();
//
// //---------注意 MapPath的 用法 ,见 WebFomr7.aspx
// MyPhone.Load(Server.MapPath("phone.xml"));
// //InnerText 可以用于 获取 节点 及所有节点的 串连值 
// //并没有得到所有节点的 属性
// Label.Text=MyPhone.InnerText.ToString();

//加载的字符串保存在 那个地方呢 ?
// XmlDocument phone=new XmlDocument();