在字符串数组中导入 XML - Windows Phone 7 [英] Importing XML in a string array - Windows Phone 7

查看:23
本文介绍了在字符串数组中导入 XML - Windows Phone 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个函数来获取xml文件的数据到一个字符串数组中

 private void ReadXml(string Dictionary, char letter){XDocument xml = XDocument.Load(Dictionary);字符串[] 字典=新字符串[2];int i=0;IEnumerablede = from el in xml.Descendants(letter.ToString())选择 el;foreach (XElement el in de){字典[i++] = el.Value.ToString();}}

但是生成的数组将我指定的 xml 标记的所有内容合并在其第一行中.

例如xml文件

并使用 xml.Descendants("B") 生成 dictionary[0]=BoaBeardictionary[1]=NULL

那么我怎样才能让每个单词都进入一个单独的数组单元?

谢谢你.

解决方案

你需要通过调用 Elements() 来遍历 标签内的元素.

例如:

foreach(var word in xml.Root.Element("B").Elements())

I'm using this function to get the data of the xml file to a string array

 private void ReadXml(string Dictionary, char letter)
    {
        XDocument xml = XDocument.Load(Dictionary);
        string[] dictionary=new string[2];
        int i=0;
        IEnumerable<XElement> de = from el in xml.Descendants(letter.ToString())
                                   select el;
        foreach (XElement el in de)
        {
            dictionary[i++] = el.Value.ToString();
        }
    }

But the array that is produced has all the contents of the xml tag I specify merged in its first line.

For example the xml file

<?xml version="1.0" encoding="Unicode"?>
<Animals>
  <A>Ant</A>
  <B>
    <word>Boa</word>
    <word>Bear</word>
  </B>
</Animals>

and with xml.Descendants("B") produces dictionary[0]=BoaBear and dictionary[1]=NULL

So how can I make it so every word gets in a separate array cell?

Thank you in adnance.

解决方案

You need to loop through the elements inside the <B> tag by calling Elements().

For example:

foreach(var word in xml.Root.Element("B").Elements())

这篇关于在字符串数组中导入 XML - Windows Phone 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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