zoukankan      html  css  js  c++  java
  • Linq to Xml遍历

            private void GetAllValues(XElement doc)
            {
                ChartValues = new List<double>();
                ChartKeys = new List<string>();

                var myValues = from pv in doc.Descendants("value")
                               select pv.Value;
                foreach (var v1 in myValues)
                    ChartValues.Add(Convert.ToDouble(v1));

                var myKeys = from pn in doc.Descendants("name")
                             //where pn.Value == "方欣科技"
                               select pn.Value;
                foreach (var v1 in myKeys)
                    ChartKeys.Add(Convert.ToString(v1));
            }

    调用:

            void ws_GetStockCompleted(object sender, GetStockCompletedEventArgs e)
            {

                if (e.Error == null)
                {
                    XElement doc = XElement.Load(new StringReader(e.Result));
                    GetAllValues(doc);
                   

                    //using (XmlReader Reader = XmlReader.Create(new StringReader(e.Result)))
                    //{
                    //    ChartValues = new List<double>();
                    //    ChartKeys = new List<string>();
                    //    for (int i = 0; i < 4; i++)
                    //    {
                    //        //Reader.ReadToFollowing("value");
                    //        //ChartValues.Add(Convert.ToInt32(Reader.ReadInnerXml()));
                    //        //Reader.ReadToFollowing("name");
                    //        //ChartKeys.Add(Reader.ReadElementContentAsString());

                    //        Reader.ReadToFollowing("value");
                    //        ChartValues.Add(Reader.ReadElementContentAsDouble());

                    //        //Stock1.Text += ChartValues[i] + "-";
                    //    }
                    //}
                }
            }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    pikachu漏洞练习之sql注入
    redis未授权访问漏洞复现
    Springboot导出Excel并下载
    Springboot使用javaMail进行邮件发送
    springboot实现上传并解析Excel
    微信提示“在浏览器打开”效果实现
    docker入门(二):镜像和容器
    centos安装mysql
    centos安装tomcat
    centos7安装jdk
  • 原文地址:https://www.cnblogs.com/starcrm/p/1353906.html
Copyright © 2011-2022 走看看