zoukankan      html  css  js  c++  java
  • /*读取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

    /*第三种方法*/
    XmlDocument doc = new XmlDocument();
    doc.Load(strXmlName);
    string strBB = "";
    XmlNode xnBB = doc.SelectSingleNode("/aaa/bb");
    if (xnBB != null)
    {
     strBB = xnTitle.InnerText;
     xnBB = null;
    }
    string strKey = "";
    XmlNode xnADD = doc.SelectSingleNode("/aaa/add");
    if (xnADD != null)
    {
     XmlNodeReader nrADD = new XmlNodeReader(xnADD);
     nrADD.MoveToContent();
     nrADD.MoveToAttribute("key");
             strKey = nrADD.Value;
             nrADD = null;
             xnADD = null;
    }

    作者:thanks       微信:-       QQ:305380844
             
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    实现一个简易版的react
    浅学virtualDom和diff算法
    148. 排序链表 归并排序 | 快速排序
    OC中的NSDictionary和NSMutableDictionary
    OC中的block
    OC中的category&Extension
    OC中判断方法是否实现
    OC的分组导航标记
    OC中程序的内存分布&类加载
    OC中的@property和@synthesize
  • 原文地址:https://www.cnblogs.com/thanks/p/5407.html
Copyright © 2011-2022 走看看