Пример #1
0
        void LoadLyricContent()
        {
            try
            {
                StreamReader streamReader = new StreamReader(StorageContainer.TitleLocation + "\\" + "LyricData.txt");
                String       line;

                while ((line = streamReader.ReadLine()) != null)
                {
                    String[] data = line.Split('|');

                    LyricObject myLyric = new LyricObject();
                    myLyric.Artist = data[0];
                    myLyric.Title  = data[1];
                    myLyric.S1     = data[2];
                    myLyric.S2     = data[3];
                    myLyric.S3     = data[4];
                    myLyric.S4     = data[5];
                    m_LyricObject.Add(myLyric);
                }

                streamReader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #2
0
        void ReadXMLFile(string filename)
        {
            //load the xml file into the XmlTextReader object.
            XmlTextReader XmlRdr = new System.Xml.XmlTextReader(filename);

            //while moving through the xml document.
            bool ListIsReady = false;

            LyricObject myLyric = new LyricObject();

            while (XmlRdr.Read())
            {
                ListIsReady = true; // guard to make sure we have font objects to fill with data..


                if (ListIsReady)
                {
                    //check the node type and look for the elements desired.
                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "Artist")
                    {
                        myLyric.Artist = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "Title")
                    {
                        myLyric.Title = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S1")
                    {
                        myLyric.S1 = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S2")
                    {
                        myLyric.S2 = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S3")
                    {
                        myLyric.S3 = XmlRdr.ReadElementContentAsString();
                    }

                    if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == "S4")
                    {
                        myLyric.S4 = XmlRdr.ReadElementContentAsString();

                        m_LyricObject.Add(myLyric);
                        myLyric = new LyricObject();
                    }
                }
            } //endwhile
        }