.Net操作XML文件
2024-09-13 15:39:19
//设置配置文件物理路径
public string xmlPath = "/manage/spider/config.xml";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//设置程序物理路径+文件物理路径
string path = Request.PhysicalApplicationPath + xmlPath;
//获取XML元素对象
XElement config = XElement.Load(path);
if (config != null)
{
//获得节点子元素
XElement eleAmazonDetailUrl = config.Element("AmazonDetailUrl");
XElement eleAmazonListUrl = config.Element("AmazonListUrl");
XElement eleHz = config.Element("Hz");
XElement eleCount = config.Element("Count");
//在页面上呈现取到的数据
if (eleAmazonDetailUrl != null)
TextBox_AmazonDetailUrl.Text = eleAmazonDetailUrl.Value;
if (eleAmazonListUrl != null)
TextBox_AmazonListUrl.Text = eleAmazonListUrl.Value;
if (eleHz != null)
TextBox_Hz.Text = eleHz.Value;
if (eleCount != null)
TextBox_Count.Text = eleCount.Value;
}
else
Response.Write(""); }
}
protected void btn_Save_Click(object sender, EventArgs e)
{
//设置XML文件路径
string path = Request.PhysicalApplicationPath + xmlPath;
//设置节点的名称和内容
XElement root = new XElement("Settings",
new XElement("AmazonDetailUrl", TextBox_AmazonDetailUrl.Text.Trim()),
new XElement("AmazonListUrl", TextBox_AmazonListUrl.Text.Trim()),
new XElement("Hz", TextBox_Hz.Text.Trim()),
new XElement("Count", TextBox_Count.Text.Trim())
);
//将元素序列化到指定路径的XML文件当中
root.Save(path);
}
最新文章
- <;<;<; request.getParameterMap()方法
- Designing for iOS: Graphics &; Performance
- html中frameset的详细使用方法
- 设想 Docker 下部署 KVM
- CC++初学者编程教程(8) VS2013配置编程助手与QT
- ajax使用及代码表示
- KEIL中逻辑分析仪的使用
- flask-sqlalchemy使用命令创建数据库
- c#下载文件选择路径控件
- 软件安装配置笔记(一)——Oracle及PLSQL Developer的安装与配置
- css学习(1)
- Windows 软件推荐大全【all】
- 使用Bind搭建DNS服务
- Ubuntu 下Apache安装和配置
- 显示器如何显示一个YUV422格式的图形
- HttpWebRequest和WebClient的用法
- mysql 主从复制原理(转)
- [9] 圆环(Ring)图形的生成算法
- EL运算符(web基础学习笔记十七)
- cxf之Exception in thread ";main"; java.lang.NoSuchMethodError: org.apache.cxf.jaxrs.provider.ProviderFactory.<;init>;(Lorg/apache/cxf/Bus;)V