天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

讀寫xml所有節(jié)點(diǎn)個(gè)人小結(jié) 和 讀取xml節(jié)點(diǎn)的數(shù)據(jù)總結(jié)

讀: 
    
//打開某文件(假設(shè)web.config在根目錄中)
    string filename=Server.MapPath("/"+ @"WebApplication1/web.config";
    XmlDocument xmldoc
= new XmlDocument();
    xmldoc.Load(filename);
 
    
//得到頂層節(jié)點(diǎn)列表
    XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
    
foreach(XmlElement element in topM)
    
{
     
if(element.Name.ToLower()=="appsettings")
     
{
 
      
//得到該節(jié)點(diǎn)的子節(jié)點(diǎn)
      XmlNodeList nodelist=element.ChildNodes;
 
      
if ( nodelist.Count >0 )
      
{
       
//DropDownList1.Items.Clear();
 
       
foreach(XmlElement el in nodelist)//讀元素值
       {
        
//DropDownList1.Items.Add(el.Attributes["key"].InnerXml);
        
//this.TextBox2.Text=el.Attributes["key"].InnerText;
        this.TextBox2.Text=el.Attributes["key"].Value;
        
this.Label1.Text=el.Attributes["value"].Value;
 
 
            
//同樣在這里可以修改元素值,在后面save。
         
//  el.Attributes["value"].Value=this.TextBox2.Text;
       }

 

      }


     }


    }


    xmldoc.Save(filename);
 
在某節(jié)點(diǎn)下增加一個(gè)元素,并設(shè)置值:
 
    
if(element.Name.ToLower()=="appsettings")
    
{
 
     XmlElement elem 
=xmldoc.CreateElement("add");
     
     element.AppendChild(elem);
     elem.InnerText
="ltp";
 
     xmldoc.Save(filename);
       
    }

 
效果:
  
<appSettings>
    
<add key="密碼" value="admin" />
    
<add>ltp</add>
  
</appSettings>
 
在某節(jié)點(diǎn)下增加一個(gè)元素,并增加兩個(gè)屬性:
    
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);
       
    }

 
效果:
  
<appSettings>
    
<add key="密碼" value="admin" />
    
<add key="ltp" value="first" />
  
</appSettings>
 
//添加空元素:
   XmlNode node=doc.CreateElement(groupname);
     node.InnerText
="";
     doc.LastChild.AppendChild(node);
 
     doc.Save(xmlfile);
 
刪除一個(gè)節(jié)點(diǎn)元素
   
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==this.comboBox1.Text)
    
{
 
     
//得到該節(jié)點(diǎn)的子節(jié)點(diǎn)
     XmlNodeList nodelist=element.ChildNodes;      
 
     
foreach(XmlElement el in nodelist)//讀元素值
     {       
      
if(el.Attributes["key"].Value==itemname)
      
{
       element.RemoveChild(el);
      }

 
     }
//循環(huán)元素
      
    }
//得到組
 
   }
//循環(huán)組

   doc.Save(xmlfile);  
//一定要保存一下,否則不起作用
 
//篩選數(shù)據(jù)
private void Reader_Xml(string pathFlie)
{
   XmlDocument Xmldoc
=new XmlDocument();
   Xmldoc.Load(pathFlie);
   XmlNodeList Record1
=Xmldoc.DocumentElement.SelectNodes(Code[@id='1'])
   
int f=0;
   
foreach(XmlNode xnode in Record1)
    
{
 
    }

}
/*讀取xml數(shù)據(jù)   兩種xml方式*/
<aaa>
     
<bb>something</bb>
     
<cc>something</cc>
</aaa>
 
<aaa>
    
<add key="123" value="321"/>
</aaa>

/*第一種方法*/
DS.ReadXml(
"your xmlfile name");
Container.DataItem(
"bb");
Container.DataItem(
"cc");
DS.ReadXmlSchema(
"your xmlfile name");
 
/*第二種方法*/
<aaa>
    
<add key="123" value="321"/>
</aaa>
如果我要找到123然后取到321應(yīng)該怎么寫呢?
 
using System.XML;
XmlDataDocument xmlDoc 
= new System.Xml.XmlDataDocument();
xmlDoc.Load(
@"c:/Config.xml");
XmlElement elem 
= xmlDoc.GetElementById("add");
string str = elem.Attributes["value"].Value
 
 
/*第三種方法:  SelectSingleNode  讀取兩種格式的xml *---/
--------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
       <ConnectionString>Data Source=yf; user id=ctm_dbo;password=123</ConnectionString>             
  </appSettings>
</configuration>
--------------------------------------------------------------------------
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;
    }
 
********************************************************************
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
       <add key="ConnectionString" value="Data Source=yf; user id=ctm_dbo;password=123" />             
  </appSettings>
</configuration>
**--------------------------------------------------------------------**
     XmlNode node=doc.SelectSingleNode("/configuration/appSettings/add");
    if(node!=null)
    {
     string k=node.Attributes["key"].Value;
     string v=node.Attributes["value"].Value;
     node=null;
    }
*--------------------------------------------------------------------*
    XmlNode node=doc.SelectSingleNode("/configuration/appSettings/add");
    if(node!=null)
    {
     XmlNodeReader nr=new XmlNodeReader(node);
     nr.MoveToContent();
    //檢查當(dāng)前節(jié)點(diǎn)是否是內(nèi)容節(jié)點(diǎn)。如果此節(jié)點(diǎn)不是內(nèi)容節(jié)點(diǎn),則讀取器向前跳至下一個(gè)內(nèi)容節(jié)點(diǎn)或文件結(jié)尾。
     nr.MoveToAttribute("value");
     string s=nr.Value;
     node=null;
    }

AspNet技術(shù)讀寫xml所有節(jié)點(diǎn)個(gè)人小結(jié) 和 讀取xml節(jié)點(diǎn)的數(shù)據(jù)總結(jié),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 91热久久免费频精品99欧美 | 无限资源在线观看播放 | 欧美成人3d动漫专区 | 日本十八禁无遮无挡漫画 | 含羞草免费完整视频在线观看 | 无码内射成人免费喷射 | 甜性涩爱下载 | 久草在在线免视频在线观看 | 中文字幕 日韩 无码 在线 | 日韩av无码在线直播 | 怡春院欧美一区二区三区免费 | 国内精品乱码卡一卡2卡三卡新区 | 欧美同志高清vivoeso | 国产av在在免费线观看美女 | 在线播放真实国产乱子伦 | 忘忧草在线社区WWW日本-韩国 | 亚洲 制服 欧美 中文字幕 | 欧美性情一线免费http | 国产成人女人在线视频观看 | 国产爱豆果冻传媒在线观看 | 久久久影院亚洲精品 | 欧美成人亚洲高清在线观看 | 国产第一页在线视频 | 国产人妻麻豆蜜桃色精 | 亚洲国产系列一区二区三区 | 欧美一区二区视频在线观看 | 国产婷婷一区二区在线观看 | 成年人视频在线免费观看 | 2020国产欧洲精品视频 | 99热在线播放 | 成品片a免人看免费 | 国产午夜精品久久理论片 | 热久久视久久精品18 | 一本道色播 | 国语92电影网午夜福利 | 青青草国产偷拍在线av | 被男按摩师添的好爽在线直播 | 人妻少妇久久久久久97人妻 | 97在线观看成人免费视频 | 久久婷婷丁香五月色综合啪免费 | 欧美日韩亚洲一区二区三区在线观看 |