예제 #1
0
        static void Main()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"../../Cars.xml");
            XmlNode root = doc.ChildNodes[1];

            //displayNode(root);

            XmlNodeList nodes = root.ChildNodes;

            foreach (XmlNode node in nodes)
            {
                //automobiles.Add(new Automobile());
                if (node.Name != "Car" || node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                try
                {
                    Automobile auto = new Automobile(node);
                    automobiles.Add(auto);
                }
                catch(ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

            }

            int i = 1;
            foreach(var auto in automobiles)
            {
                Console.WriteLine(i++);
                auto.ShowInfo();
                Console.WriteLine();
            }

            Console.WriteLine();

            // find auto with min year
            Automobile new_auto = new Automobile();
            new_auto.year = 0;
            foreach (var auto in automobiles)
            {
                if(new_auto.year < auto.year)
                {
                    new_auto = auto;
                }
            }
            Console.WriteLine("New auto: ");
            new_auto.ShowInfo();

            Console.ReadLine();
        }
예제 #2
0
 public Automobile(XmlNode node)
 {
     manufactured = GetNodeElement(node, "Manufactured");
     model = GetNodeElement(node, "Model");
     color = GetNodeElement(node, "Color");
     speed = Convert.ToInt32(GetNodeElement(node, "Speed"));
     year = Convert.ToInt32(GetNodeElement(node, "Year"));
     if(node["Inside"] != null)
     {
         auto = new Automobile(node["Inside"]["Car"]);
     }
 }