全国统一热线:
028-86758058
18980748058
购买流程
付款方式
常见问题
在线提问
续租服务
购物车(
0
件)
用户名:
密 码:
记住
首 页
HOME
域名注册
DOMAIN
虚拟主机
WEB HOST
成品网站超市
AUTO Site
VPS主机
VPS SERVER
云 主 机
CLOUD HOST
租用托管
SERVER
海外主机
HK HOST
代理专区
AGENT
客服中心
SERVICE
站长教程
SERVICE
欢迎光临西部数据云计算中心,我们将竭诚为您提供最优质的服务!
中文域名
域名转入
域名转出
DNS管理
动态域名
获取域名证书
域名停放
域名过户
集群主机
双线主机
基本主机
港台主机
论坛主机
Linux主机
Vip合租主机
超G型主机
ASP.net主机
Java主机
智能建站主机
网店主机
美国主机
数据库
成品网站超市
智能建站主机
集群VPS主机
国内VPS主机
香港VPS主机
美国VPS主机
云主机介绍
云主机购买
服务器租用
主机托管
常见问题
香港主机
港台主机
美国主机
国内免备案
步骤流程
代理级别
代理合同
代理模式
代理优势
在线申请
产品列表
常见问题
代理商分布图
常见问题
有问必答
跟踪提问
购买流程
产品价格
付款方式
常用软件
网站备案
续租服务
汇款确认
相关文档
联系我们
域名资讯
主机资讯
行业动态
网页制作
php教程
mysql教程
域名资讯
云计算资讯
网络编程
您当前的位置:
首页
>
网络编程
>
Net教程
XML文件修改节点属性值(多种方法)
时间:2015-01-29 来源:互联网 作者:佚名
xml 文件内容
:
复制代码
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<subtitles>
<info>
<content>最新通告:五一放假七天!请各教员悉知</content>
<speed>4</speed>
<color>red</color>
</info>
</subtitles>
C#代码
:
复制代码
代码如下:
XmlDocument xml = new XmlDocument();
xml.Load(context.Server.MapPath("~/js/XMLFile.xml"));
XmlNode xn = xml.DocumentElement;
foreach (XmlNode node in xn.ChildNodes)
{
if (node.Name == "info")
{
node["content"].InnerText = content;
node["speed"].InnerText = speed;
node["color"].InnerText = color;
}
}
xml.Save(context.Server.MapPath("~/js/XMLFile.xml"));
另外两种办法
:
修改xml字符串的某个节点的属性值,如下:
复制代码
代码如下:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<fsdlconfig userName=\"ss\" password=\"134\"/>");
XmlAttribute att =(XmlAttribute)doc.SelectSingleNode("/fsdlconfig/@userName");
Console.WriteLine(att.Value);
att.Value = "test";
string str = doc.OuterXml;
节点userName的值由原来的"ss",变成了"test",然后用doc.OuterXml保存修改后的xml为字符串。
另一种方式
:
复制代码
代码如下:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<fsdlconfig userName=\"ss\" password=\"134\"/>");
XmlElement att = (XmlElement)doc.FirstChild;
att.SetAttribute("userName","test");
string str = doc.OuterXml;
来顶一下
返回首页
推荐资讯
Asp.net GridView使用大全(分页实现
GridView自带的分页功能实现:要实现GrdView分页的功能操作如
基于asp.net下使用jquery实现ajax的
无论是jquery还是ajax在今天来讨论已经很落后了,网上也有非
相关文章
IIS 浏览aspx页面出现无法显示XML页的解决方法分享
深入分析XmlSerializer对象的Xml序列化与反序列化的示
解析linq to xml操作XML的示例分析
.net 操作xml的简单方法及说明
asp.net代码中修改web.config节点的具体方法
HTTP错误500.19解决方法(定义了重复的节点)
asp.net 将一个图片以二进制值的形式存入Xml文件中的实
.NET更新Xml中CDATA内容的方法实例
asp.net TreeView与XML三步生成列表树
解析在.net中使用XSLT转换xml文档的示例详解
栏目更新
栏目热门
返回首页
关于我们
联系我们
付款方式
价格总览
资讯中心
友情链接
媒体关注
有问必答
投诉建议
网站备案
《中华人民共和国增值电信业务经营许可证》编号:川B2-20080058号
官方网址:
xibushuju.com
西部数据
Copyright © 2002~2015
天府快车
版权所有
电话总机:
028-86758058
(50线) 传真:
028-86758058