示例#1
0
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"..\\..\\Cars.xml");
            XmlNode root = doc.ChildNodes[1];
            //NodeWorking.displayNode(root);

            List<Automobile> automobiles = new List<Automobile>();

            var children = root.ChildNodes;

            foreach (XmlNode child in children)
            {
                if (child.Name.ToLower() == "car")
                {
                    automobiles.Add(new Automobile(child));
                }
            }

            var ordering = from auto in automobiles
                           orderby auto.year descending
                           select auto;

            var mostNewCar = ordering.First();

            Automobile testForRecording = new Automobile("USA", "Impala", "Red", 1967, 100, "7sbj2k21", "13.jpg", automobiles[0]);
            testForRecording.addToXMLAsChild(doc, root);
            doc.Save(@"..\\..\\Cars.xml");

            Console.ReadKey();
        }
示例#2
0
 public Automobile(string manufactured_, string model_, string color_, int year_, int speed_, string hash_ = null, string image_ = null, Automobile inner_ = null)
 {
     manufactured = manufactured_;
     model = model_;
     color = color_;
     year = year_;
     speed = speed_;
     hash = hash_;
     image = image_;
     inner = inner_;
 }
示例#3
0
        // constructors
        public Automobile(XmlNode xmlAuto)
        {
            var attributes = xmlAuto.Attributes;

            foreach (XmlAttribute attr in attributes)
            {
                switch (attr.Name.ToLower())
                {
                    case "image":
                        image = attr.Value;
                        break;

                    case "color":
                        color = attr.Value;
                        break;

                    case "year":
                        year = int.Parse(attr.Value);
                        break;

                    case "hash":
                        hash = attr.Value;
                        break;
                }
            }

            var children = xmlAuto.ChildNodes;

            foreach (XmlNode child in children)
            {
                switch (child.Name.ToLower())
                {
                    case "manufactured":
                        manufactured = child.ChildNodes[0].Value;
                        break;

                    case "model":
                        model = child.ChildNodes[0].Value;
                        break;

                    case "year":
                        year = int.Parse(child.ChildNodes[0].Value);
                        break;

                    case "color":
                        color = child.ChildNodes[0].Value;

                        var attr = child.Attributes;

                        if (attr.Count > 0 && attr["metallic"] != null && attr["metallic"].Value == "true")
                        {
                            color += ", metallic";
                        }

                        break;

                    case "speed":
                        speed = int.Parse(child.ChildNodes[0].Value);
                        break;

                    case "inside":
                        inner = new Automobile(child.ChildNodes[0]);
                        break;
                }
            }
        }