コード例 #1
0
        /// <summary>
        /// Create a SmartCard from the information contained in an XmlDocument.
        /// </summary>
        /// <param name="xmlDoc">The document to process.</param>
        /// <returns>A new SmartCard built from the XmlDocument.</returns>
        /// <exception cref="InvalidSmartCardException">
        /// If the deserialization of the smartcard failed for some reason.
        /// </exception>
        protected SmartCard DeserializeXML(XmlDocument xmlDoc)
        {
            SmartCard    smartCard;
            XmlNode      rootNode;
            XmlNodeList  nodeList;
            XmlAttribute attrNode;
            ISerializer  serialize;
            object       content;

            // Make the new smart card.
            smartCard = new Types.SmartCard();

            // Get the root node.
            rootNode = xmlDoc.DocumentElement;
            if (rootNode == null)
            {
                return(smartCard);
            }

            // Get the smart card node.
            nodeList = xmlDoc.GetElementsByTagName("sc");
            if (nodeList.Count > 0)
            {
                // Get the part number attribute.
                attrNode = ( XmlAttribute )nodeList[0].Attributes.GetNamedItem("pn");
                if (attrNode != null)
                {
                    smartCard.PartNumber = attrNode.Value;
                }

                // Get the program date attribute.
                attrNode = ( XmlAttribute )nodeList[0].Attributes.GetNamedItem("pd");
                if (attrNode != null)
                {
                    smartCard.ProgramDate = DateTime.Parse(attrNode.Value);
                }
            }

            try
            {
                // Get all of the cylinder content nodes.
                nodeList = xmlDoc.GetElementsByTagName("c");
                foreach (XmlNode child in nodeList)
                {
                    // Deserialize all of the cylinder children.
                    serialize = new CylinderXMLSerializer();
                    content   = serialize.Deserialize(child.OuterXml);
                    smartCard.Add(content, serialize);
                }
            }
            catch (Exception e)
            {
                throw new InvalidSmartCardException(e);
            }

            return(smartCard);
        }