C# 在WindowsPhone8中解析XML

C# 在WindowsPhone8中解析XML,c#,xml,windows-phone-8,linq-to-xml,C#,Xml,Windows Phone 8,Linq To Xml,我有一个如下所示的xml文件 <sections> <section> <name>QLD Mosques</name> <stations> <station> <id>101</id> <pn>true</pn> <name>Kuraby Mo

我有一个如下所示的xml文件

<sections>
   <section>
      <name>QLD Mosques</name>
      <stations>
         <station>
            <id>101</id>
            <pn>true</pn>
            <name>Kuraby Mosque</name>
            <url>http://sb2110.ultrastream.co.uk/kuraby</url>
            <icon>...</icon>
         </station>
         <station>
            <id>102</id>
            <pn>true</pn>
            <name>Gold Coast Mosque</name>
            <url>http://sb2110.ultrastream.co.uk/goldcoast</url>
            <icon>http://www.juju.net.au/mosquereceivers/images/icons/gc.jpg</icon>
         </station>
         <station>...</station>
      </stations>
   </section>
   <section>
      <name>NZ Mosques</name>
      <stations>...</stations>
   </section>
   <section>
      <name>Islamic Radio Stations</name>
      <stations>...</stations>
   </section>
</sections>

昆士兰清真寺
101
真的
库拉比清真寺
http://sb2110.ultrastream.co.uk/kuraby
...
102
真的
黄金海岸清真寺
http://sb2110.ultrastream.co.uk/goldcoast
http://www.juju.net.au/mosquereceivers/images/icons/gc.jpg
...
新西兰清真寺
...
伊斯兰广播电台
...
我想显示所有车站的名称,其中有“部分”命名为“昆士兰清真寺”。 例如,我的结果将是“库拉比清真寺,黄金海岸清真寺,…”。 我怎样才能达到这个结果

N:B: 我可以使用以下代码显示“section”标签下的名称(给出QLD清真寺、新西兰清真寺、伊斯兰电台的结果):

public static List<MyData> channel_main_list = new List<MyData>();

    public MainChannelList()
    {
        InitializeComponent();


        WebClient client = new WebClient();
        client.OpenReadCompleted += client_OpenReadCompleted;
        client.OpenReadAsync(new Uri("http://www.juju.net.au/mosquereceivers/Stations.xml",UriKind.Absolute));

    }

    void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error != null)
            return;

        Stream str = e.Result;

        string node = "section";

        XDocument loadedData = XDocument.Load(str);

        try
        {
            foreach (var item in loadedData.Descendants(node))
            {

                try
                {
                    MyData m = new MyData();
                    m.channel_name = item.Element("name").Value;

                    channel_main_list.Add(m);
                }
                catch (Exception)
                {

                    MessageBox.Show("Problem");
                }



            }

            listBox.ItemsSource = channel_main_list;

        }
        catch (Exception)
        {
            MessageBox.Show("Connectivity Problem");
        }
    }
public static List channel_main_List=new List();
公共主频道列表()
{
初始化组件();
WebClient客户端=新的WebClient();
client.OpenReadCompleted+=客户机_OpenReadCompleted;
client.OpenReadAsync(新Uri(“http://www.juju.net.au/mosquereceivers/Stations.xml“,UriKind.Absolute”);
}
无效客户端\u OpenReadCompleted(对象发送方,OpenReadCompletedEventArgs e)
{
如果(例如错误!=null)
返回;
Stream=e.结果;
string node=“节”;
XDocument loadedata=XDocument.Load(str);
尝试
{
foreach(loadedData.subjects(节点)中的变量项)
{
尝试
{
MyData m=新的MyData();
m、 通道名称=item.Element(“名称”).Value;
频道主列表。添加(m);
}
捕获(例外)
{
MessageBox.Show(“问题”);
}
}
listBox.ItemsSource=频道\主\列表;
}
捕获(例外)
{
MessageBox.Show(“连接问题”);
}
}

这是一种可能的方法,假设XML结构是一致的,并且始终可以找到正在搜索的
名称:

var result=loadedData.substands(“节”)
其中(o=>(字符串)o.Element(“名称”)==“QLD清真寺”)
.要素(“站”)
.要素(“车站”)
.要素(“名称”);

在“section”标签下张贴相关代码,说明如何获得姓名,这样我们就可以从该代码开始,但我只能得到名字,即“Kuraby清真寺”,因此,我还需要所有名称,如“Gold Coast Mosque”等。我应该学习什么来了解这些问题。你能给我一些好的教程链接来学习这些解析吗?再说一遍,我怎样才能得到站点“url”,“图标”呢@har07@imonbayazid搜索“Linq到XML”参考/教程。祝你好运再说一遍,我怎样才能得到站“网址”,“图标”太@哈