从xml文件中读取 - Windows phone圣经应用程序 [英] Reading from xml file - Windows phone Bible App

查看:119
本文介绍了从xml文件中读取 - Windows phone圣经应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是视觉工作室2012中的Windows手机的新用户,我想用我的母语非洲语言建立一个圣经应用程序。我在从xml文件中阅读书名,章节和经文时遇到问题。这就是我所做的。请帮忙。

XML FIlE

Hi,
I am new to windows phone in visual studio 2012 and I would like to build a bible app in my native african language. I'm having a problem with reading Book Title, Chapter and verse from an xml file. Here is what I have done. Please help.
XML FIlE

<?xml version="1.0" encoding="utf-8" ?>

<bible translation="King James Version">
  <testament name="Old">
    <book name="Genesis">
      <chapter number="1">
        <verse number="1">In the beginning God created the heaven and the earth.</verse>
        <verse number="2">And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</verse>
      </chapter>
    </book>
  </testament>
</bible>





======== ==========

C#代码





==================
C# CODE

namespace BibleApp
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

 XDocument loadedData = XDocument.Load("Bible.xml");
            var SearchData = from c in loadedData.Descendants("testament").Descendants("book").Descendants("chapter").Descendants("verse")
                             where (bool)c.Parent.Parent.Parent.Attribute("name")
                             where (bool)c.Parent.Parent.Attribute("name")
                             where (bool)c.Parent.Attribute("number")
                             select new BibleLoad
                             {
                                 VerseNumber = (string)c.Attribute("number"),
                                 BibleText = (string)c.Value.ToString(),
                                 TheFontSize = FontSize
                             };
            TheList.ItemsSource = SearchData;
            TheList.Visibility = Visibility.Visible;

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
        public class BibleLoad
        {

            string myTestament;
            string myBook;
            string myChapter;
            string myVerse;
            double fontSize;
            string bibleText;



            public string Testament
            {
                get { return myTestament; }
                set { myTestament = value; }
            }

            public string Book
            {
                get { return myBook; }
                set { myBook = value; }
            }
            public string Chapter
            {
                get { return myChapter; }
                set { myChapter = value; }
            }
            public string VerseNumber
            {
                get { return myVerse; }
                set { myVerse = value; }
            }

            public double TheFontSize
            {
                get { return fontSize; }
                set { fontSize = value; }
            }

            public string BibleText
            {
                get { return bibleText; }
                set { bibleText = value; }
            }
        }
}

推荐答案

试试这个:

Try this:
var verses = from v in xdoc.Elements("bible").Elements("testament").Elements("book").Elements("chapter").Elements("verse")
        select new {
            VerseId = v.Attribute("number").Value,
            VerseText = v.Value
            };





它应该返回:



It should return:

VerseId VerseText
1       In the beginning God created the heaven and the earth.
2       And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.





我不知道如何将数据加载到<$ c $中c> BibleLoad class。在我看来,你需要重新设计它,以便能够存储书籍,章节和经文的集合。

请检查它:演练:创建自己的集合类 [ ^ ]



I have no idea how to load data into your BibleLoad class. In my opinion, you need to redesign it, to be able to store the collection of books, chapters and verses.
Please, check it: Walkthrough: Creating Your Own Collection Class[^]


这篇关于从xml文件中读取 - Windows phone圣经应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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