已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/打开某文件(假设web.config在根目录中) string filename=Server.MapPath(/) + WebApplication1web.config; XmlDocument xmldoc= new XmlDocument(); xmldoc.Load(filename); /得到顶层节点列表 XmlNodeList topM=xmldoc.DocumentElement.ChildNodes; foreach(XmlElement element in topM) if(element.Name.ToLower()=appsettings) /得到该节点的子节点 XmlNodeList nodelist=element.ChildNodes; if ( nodelist.Count 0 ) /DropDownList1.Items.Clear(); foreach(XmlElement el in nodelist)/读元素值 /DropDownList1.Items.Add(el.Attributeskey.InnerXml); /this.TextBox2.Text=el.Attributeskey.InnerText; this.TextBox2.Text=el.Attributeskey.Value; this.Label1.Text=el.Attributesvalue.Value; /同样在这里可以修改元素值,在后面save。 / el.Attributesvalue.Value=this.TextBox2.Text; xmldoc.Save(filename); 效果: /添加空元素: XmlNode node=doc.CreateElement(groupname); node.InnerText=; doc.LastChild.AppendChild(node); doc.Save(xmlfile);删除一个节点元素 string itemname=this.listBox1.SelectedItem.ToString(); this.listBox1.Items.Remove(this.listBox1.SelectedItem); /begin del xmlfile XmlDocument doc=new XmlDocument(); doc.Load(xmlfile); XmlNodeList topM=doc.DocumentElement.ChildNodes; foreach(XmlElement element in topM) if(element.Name=boBox1.Text) /得到该节点的子节点 XmlNodeList nodelist=element.ChildNodes; foreach(XmlElement el in nodelist)/读元素值 if(el.Attributeskey.Value=itemname) element.RemoveChild(el); /循环元素 /得到组 /循环组 doc.Save(xmlfile); /一定要保存一下,否则不起作用/筛选数据private void Reader_Xml(string pathFlie) XmlDocument Xmldoc=new XmlDocument(); Xmldoc.Load(pathFlie); XmlNodeList Record1=Xmldoc.DocumentElement.SelectNodes(Codeid=1) int f=0; foreach(XmlNode xnode in Record1) /*/*读取xml数据 两种xml方式*/ something something /*/*第一种方法*/DS.ReadXml(your xmlfile name);Container.DataItem(bb);Container.DataItem(cc);DS.ReadXmlSchema(your xmlfile name);/*/*第二种方法*/ 如果我要找到123然后取到321应该怎么写呢?using System.XML;XmlDataDocument xmlDoc = new System.Xml.XmlDataDocument();xmlDoc.Load(c:Config.xml);XmlElement elem = xmlDoc.GetElementById(add);string str = elem.Attributesvalue.Value/*/*第三种方法: SelectSingleNode 读取两种格式的xml *-/- Data Source=yf; user id=ctm_dbo;password=123在某节点下增加一个元素,并设置值: if(element.Name.ToLower()=appsettings) XmlElement elem =xmldoc.CreateElement(add); element.AppendChild(elem); elem.InnerText=ltp; xmldoc.Save(filename); 效果: ltp在某节点下增加一个元素,并增加两个属性: if(element.Name.ToLower()=appsettings) XmlElement elem =xmldoc.CreateElement(add); element.AppendChild(elem); XmlAttribute xa=xmldoc.CreateAttribute(key); xa.Value=ltp; XmlAttribute xa2=xmldoc.CreateAttribute(value); xa2.Value=first; elem.SetAttributeNode(xa); elem.SetAttributeNode(xa2); xmldoc.Save(filename);-XmlDocument doc = new XmlDocument();doc.Load(strXmlName); XmlNode node=doc.SelectSingleNode(/configuration/appSettings/ConnectionString); if(node!=null) string k1=node.Value; /null string k2=node.InnerText;/Data Source=yf; user id=ctm_dbo;password=123 string k3=node.InnerXml;/Data Source=yf; user id=ctm_dbo;password=123 node=null; * *-* XmlNode node=doc.SelectSingleNode(/configuration/appSettings/add); if(node!=null) string k=node.Attributeskey.Value; string v=node.Attributesvalue.Value; node=null; *-* XmlNode node=doc.SelectSingleNode(/configuration/appSettings/add); if(node!=null) Xml
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年科普知识题库100道附答案【模拟题】
- 2026年初级经济师之初级经济师财政税收考试题库300道附答案(考试直接用)
- 浙江国企招聘-2025台州市开发投资集团有限公司招聘4人历年真题汇编附答案解析
- 中国汽研2026校园招聘历年真题汇编带答案解析
- 2025河南新乡同盟新材料科技研发中心有限公司招聘工作人员4人模拟试卷带答案解析
- 2025北京大学汉语教育学院招聘劳动合同制工作人员招聘1人模拟试卷附答案解析
- 2026应急管理部所属单位第一批次招聘230人历年真题汇编带答案解析
- 2025四川自贡汇东人力资源发展有限责任公司招聘人员8人笔试备考试卷附答案解析
- 2025年河北张家口怀来技师学院公开选聘高技能人才1名参考题库附答案解析
- 2025江西九江永修中环物产管理有限公司招聘工作人员1人笔试备考试卷带答案解析
- 2023年光器件工艺工程师年终总结及下一年展望
- 催化裂化-认识催化裂化(石油加工课件)
- 3.3《不简单的杠杆》课件
- 气管切开换药的护理操作程序(图解)
- ISO 22000-2018食品质量管理体系-食品链中各类组织的要求(2023-雷泽佳译)
- GB/T 711-1988优质碳素结构钢热轧厚钢板和宽钢带
- 无菌物品的管理培训课件
- ArcGIS应用基础培训课件
- 中小学家长会-九年级第一次家长会课件-1课件
- 一代雄狮拿破仑
- 高空吊板(蜘蛛人)安全技术交底和安全检查表
评论
0/150
提交评论