首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求教这段xml如何读出

2012-01-11 
求教这段xml怎么读出??xml version1.0?!--系统参数--SystemOptions BackGroundPicturePath Sys

求教这段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();


//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 个 页面,一个写,一个读, 试一试

热点排行