Exemplo n.º 1
0
        public static MobileAccount GetByName(string adress, string name)
        {
            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement NameElement      = MobileAccounts.Element("Name");
                XElement LastNameElement  = MobileAccounts.Element("LastName");
                XElement BirthDateElement = MobileAccounts.Element("BirthDate");
                XElement EmailElement     = MobileAccounts.Element("Email");
                XElement NumberElement    = MobileAccounts.Element("Number");

                if (name == NameElement.Value)
                {
                    MobileAccount user = new MobileAccount();
                    user.Name      = NameElement.Value;
                    user.LastName  = LastNameElement.Value;
                    user.BirthDate = DateTime.Parse(BirthDateElement.Value);
                    user.Email     = EmailElement.Value;
                    user.Number    = Int32.Parse(NumberElement.Value);
                    return(user);
                }
            }
            return(default(MobileAccount));
        }
Exemplo n.º 2
0
        public static List <string> Sample(string adress, string fieldName)
        {
            List <string> fields = new List <string>();

            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement SomeField = MobileAccounts.Element(fieldName);
                fields.Add(SomeField.Value.ToString());
            }
            return(fields);
        }
Exemplo n.º 3
0
        public static void RemuveByName(string adress, string name)
        {
            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement NameElement = MobileAccounts.Element("Name");

                if (name == NameElement.Value)
                {
                    MobileAccounts.RemoveAll();
                    Console.WriteLine(name + " was successfully removed");
                }
            }
            xdoc.Save("removed" + adress);
        }
Exemplo n.º 4
0
        public static void FindByName(string adress, string name)
        {
            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement NameElement      = MobileAccounts.Element("Name");
                XElement LastNameElement  = MobileAccounts.Element("LastName");
                XElement BirthDateElement = MobileAccounts.Element("BirthDate");
                XElement EmailElement     = MobileAccounts.Element("Email");
                XElement NumberElement    = MobileAccounts.Element("Number");
                if (name == NameElement.Value)
                {
                    Console.WriteLine("Name: {0} Last name: {1} Birth date: {2} Email: {3} Number: {4}",
                                      NameElement.Value, LastNameElement.Value, BirthDateElement.Value,
                                      EmailElement.Value, NameElement.Value);
                }
            }
        }