Exemple #1
0
        public Student GetXML()
        {
          
              Student sd = new Student();

            sd.InputStudent();
            FileStream stream = new FileStream("students.xml", FileMode.Open);

            XmlTextReader xmlReader=new XmlTextReader(stream);;
            xmlReader.WhitespaceHandling = WhitespaceHandling.None;
         
            // var xmlReader = new XmlDocument();
            //xmlReader.Load("students.xml");
            while (xmlReader.Read())
            {               
                   
                    if (xmlReader.Name.Equals("Age"))
                {
                    xmlReader.Read();
                    if (xmlReader.NodeType == XmlNodeType.Text)
                    {
                        sd.age = Convert.ToInt32(xmlReader.Value);
                        Console.WriteLine(sd.age);
                    }
                   //string q;
                   // q = xmlReader.Value;                   
                 //   sd.age = Convert.ToInt32(q.Split(new char[] { ' ','\n','\t','\r' }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (xmlReader.Name.Equals("firstName"))
                {
                   // xmlReader.Read();
                    sd.firstName = xmlReader.Value;
                    Console.WriteLine(sd.firstName);
                }
                if (xmlReader.Name.Equals("lastName"))
                {
                    xmlReader.Read();
                    sd.lastName = xmlReader.Value;
                }
                if (xmlReader.Name.Equals("surName"))
                {
                    xmlReader.Read();
                    sd.surName = xmlReader.Value;
                }
                if (xmlReader.Name.Equals("group"))
                {
                    xmlReader.Read();
                    sd.group = xmlReader.Value;
                }
                if (xmlReader.Name.Equals("Profile"))
                {
                    xmlReader.Read();
                    if (xmlReader.Value== "Developer")
                    sd.profile = 1;
                    if (xmlReader.Value == "Admin")
                        sd.profile = 2;
                    if (xmlReader.Value == "Desiner")
                        sd.profile = 3;
                }
                if (xmlReader.Name.Equals("Marks"))
                {
                    string s;
                    xmlReader.Read();
                    s = xmlReader.Value;
                    string[] smarks= s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (sd.profile == 1)
                    {

                        sd.mark[0] = new int[smarks.Length];
                        for (int i = 0; i < smarks.Length; i++)
                        {
                           
                            sd.mark[0][i] =Convert.ToInt32 (smarks[i]);
                        }

                    }
                    if (sd.profile == 2)
                    {
                        sd.mark[1] = new int[smarks.Length];
                        for (int i = 0; i < smarks.Length; i++)
                        {
                                sd.mark[1][i] = Convert.ToInt32(smarks[i]);
                            }
                    }
                    if (sd.profile == 3)
                    {
                        sd.mark[2] = new int[smarks.Length];
                        for (int i = 0; i < smarks.Length; i++)
                        {
                                sd.mark[2][i] = Convert.ToInt32(smarks[i]);
                            }
                    }
                }

            }
        //    Console.WriteLine(sd.age);
            sd.InputInXml();
            xmlReader.Close();
           sd.PrintStudent();
           return  sd;
           
        }