阅读XML如何选择元素 [英] Read XML how to select element

查看:85
本文介绍了阅读XML如何选择元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在xml中有这个文件我的软件写的是c#

地址是 http://asus1.accu-weather.com/widget/asus1/weather-data.asp?location=Pisa&metric=1&langId=1 [ ^ ]



i想要选择类似节点的节点并选择像temp这样的元素

c#步骤中的步骤谢谢你



我尝试了什么:



i尝试使用microsoft示例,但我不明白

hello i have this file in xml my software to write is c#
the address is http://asus1.accu-weather.com/widget/asus1/weather-data.asp?location=Pisa&metric=1&langId=1[^]

i want to select node like units and select element like temp

how too in c# step for step thank you

What I have tried:

i try with microsoft example but i don't understand

推荐答案

试试这个,阅读单位节点



try this, to read the units node

String url= "http://asus1.accu-weather.com/widget/asus1/weather-data.asp?location=Pisa&metric=1&langId=1";            
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(url);
            XmlNode unitsNode = xmlDoc.DocumentElement.GetElementsByTagName("units")[0];
            foreach (XmlElement item in unitsNode)
                Console.WriteLine(item.Name + "=>" + item.InnerText); 

            Console.ReadLine();





你应该开始学习xml来使用任何xml树结构。

xml intro [ ^ ]

C#XML教程 [ ^ ]


这篇关于阅读XML如何选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆