本站首页    管理页面    写新日志    退出

The Neurotic Fishbowl

读取xml节点的数据总结
lhsunrice 发表于 2007/5/29 8:56:38

读取xml节点的数据总结  /*读取xml数据   两种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应该怎么写呢? 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();    //检查当前节点是否是内容节点。如果此节点不是内容节点,则读取器向前跳至下一个内容节点或文件结尾。     nr.MoveToAttribute("value");     string s=nr.Value;     node=null;    }

阅读全文(2087) | 回复(0) | 编辑 | 精华

 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)

 
 



The Neurotic Fishbowl

.: 公告

为了爱情,为了梦想~~~


Bloginess

«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

.: 我的分类(专题)

首页(5)


In the Bowl

.: 最新日志

JavaScript脚本读取xml数据到
读取xml节点的数据总结
读写xml所有节点个人小结
用javascript操作xml
怎样通过XSLT把编辑的内容嵌入网页呢?


.: 最新回复

回复:读写xml所有节点个人小结


The Fishkeeper
blog名称:[小鸟天堂]
日志总数:5
评论数量:2
留言数量:-3
访问次数:44397
建立时间:2007年5月22日



Text Me

.: 留言板

签写新留言

[小鸟天堂]都开到这来了!


Other Fish in the Sea

.: 链接


http://blogger.org.cn/blog/listblogger.asp?usertype=16  。数据挖掘者 。

http://blogger.org.cn/blog/listblogger.asp?usertype=3   。XMLer 。

 




站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.031 second(s), page refreshed 144799631 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号