Beispiel #1
0
        public static CacheOrder ParseXml(string xml)
        {
            try
            {
                // parse the XML into a document
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlElement orderElement = doc.GetElementsByTagName(orderTag)[0] as XmlElement;

                // create the pieces from XML elements
                OrderInfo order = new OrderInfo();
                order.ParseOrderDetailsXml(orderElement);

                XmlElement existingNotesElement = orderElement.GetElementsByTagName(existingNotesTag)[0] as XmlElement;
                order.Notes = NoteInfo.ParseNotes(existingNotesElement);

                XmlElement newNotesElement = orderElement.GetElementsByTagName(newNotesTag)[0] as XmlElement;
                NoteInfo[] newNotes        = NoteInfo.ParseNotes(newNotesElement);

                XmlElement existingPhotosElement = orderElement.GetElementsByTagName(existingPhotosTag)[0] as XmlElement;
                order.Photos = PhotoInfo.ParsePhotos(existingPhotosElement);

                XmlElement  newPhotosElement = orderElement.GetElementsByTagName(newPhotosTag)[0] as XmlElement;
                PhotoInfo[] newPhotos        = PhotoInfo.ParsePhotos(newPhotosElement);

                XmlElement  statusElement = orderElement.GetElementsByTagName(statusTag)[0] as XmlElement;
                CacheStatus status        = (CacheStatus)Enum.Parse(typeof(CacheStatus), statusElement.InnerText);

                // create the cache order object from the pieces
                return(new CacheOrder(order, newNotes, newPhotos, status));
            }
            catch
            {
                return(null);
            }
        }