C# 读取XML文件,并且可以显示到页面!
2个回答
推荐于2016-02-28
展开全部
private void IniClientSet()
{
try
{
string clientFileName = @"\updcfg\UpdClientSet.xml";//客户端配置文件位置
xmlDoc.Load(Application.StartupPath + clientFileName);
#region "子节点"
XmlNode node;
node = XmlUtil.GetSingleNode(xmlDoc, "//location");//服务器位置信息
ClientSet.Location = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UpdateFolder");//更新文件夹
ClientSet.UpdateFolder = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UserName");//用户名
ClientSet.UserName = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//Password");//密码
ClientSet.Password = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//ServerConfigFile");//服务器配置文件名
ClientSet.ServerConfigFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UpdFileList");//更新文件列表名
ClientSet.UpdFileList = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//IsOpenUpdate");//是否启用更新-默认1,1=是 0=否
ClientSet.IsOpenUpdate = Convert.ToInt32(node.InnerText);
node = XmlUtil.GetSingleNode(xmlDoc, "//LocalBackupFile");//本地备份文件夹名-BACK
ClientSet.LocalBackupFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//LocalLogFile");//本地日志文件夹名-LOG\\UpdLog
ClientSet.LocalLogFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UpdateFinishStartFile");//更新完成后要启动的执行文件
ClientSet.UpdateFinishStartFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//CreatVersion");//当前版本号
ClientSet.CreatVersion = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//LastUpdateTime");//最后更新时间
ClientSet.LastUpdateTime = Convert.ToDateTime(node.InnerText);
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
{
try
{
string clientFileName = @"\updcfg\UpdClientSet.xml";//客户端配置文件位置
xmlDoc.Load(Application.StartupPath + clientFileName);
#region "子节点"
XmlNode node;
node = XmlUtil.GetSingleNode(xmlDoc, "//location");//服务器位置信息
ClientSet.Location = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UpdateFolder");//更新文件夹
ClientSet.UpdateFolder = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UserName");//用户名
ClientSet.UserName = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//Password");//密码
ClientSet.Password = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//ServerConfigFile");//服务器配置文件名
ClientSet.ServerConfigFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UpdFileList");//更新文件列表名
ClientSet.UpdFileList = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//IsOpenUpdate");//是否启用更新-默认1,1=是 0=否
ClientSet.IsOpenUpdate = Convert.ToInt32(node.InnerText);
node = XmlUtil.GetSingleNode(xmlDoc, "//LocalBackupFile");//本地备份文件夹名-BACK
ClientSet.LocalBackupFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//LocalLogFile");//本地日志文件夹名-LOG\\UpdLog
ClientSet.LocalLogFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//UpdateFinishStartFile");//更新完成后要启动的执行文件
ClientSet.UpdateFinishStartFile = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//CreatVersion");//当前版本号
ClientSet.CreatVersion = node.InnerText;
node = XmlUtil.GetSingleNode(xmlDoc, "//LastUpdateTime");//最后更新时间
ClientSet.LastUpdateTime = Convert.ToDateTime(node.InnerText);
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
2013-05-17
展开全部
XPathDocument doc = new XPathDocument(Server.MapPath("路径"));
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator ite = nav.Select("/父节点/子节点");
//移动到下一个节点,下一个节点是文字节点。
ite.MoveNext();
Response.Write (ite.Current.Value);
ite = nav.Select("/notepad/content");
//移动到下一个节点,下一个节点是文字节点。
ite.MoveNext();
Response.Write (ite.Current.Value);
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator ite = nav.Select("/父节点/子节点");
//移动到下一个节点,下一个节点是文字节点。
ite.MoveNext();
Response.Write (ite.Current.Value);
ite = nav.Select("/notepad/content");
//移动到下一个节点,下一个节点是文字节点。
ite.MoveNext();
Response.Write (ite.Current.Value);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询