Example #1
0
        /// <summary>Read Element named mime-type. </summary>
        private MimeType ReadMimeType(XmlElement element)
        {
            string   name        = null;
            string   description = null;
            MimeType type        = null;
            var      attrs       = element.Attributes;

            for (var i = 0; i < attrs.Count; i++)
            {
                var attr = (XmlAttribute)attrs.Item(i);

                if (attr.Name.Equals("name"))
                {
                    name = attr.Value;
                }
                else if (attr.Name.Equals("description"))
                {
                    description = attr.Value;
                }
            }
            if ((name == null) || (name.Trim().Equals("")))
            {
                return(null);
            }

            try
            {
                System.Diagnostics.Trace.WriteLine("Mime type:" + name);
                type = new MimeType(name);
            }
            catch (MimeTypeException mte)
            {
                // Mime Type not valid... just ignore it
                System.Diagnostics.Trace.WriteLine(mte + " ... Ignoring!");
                return(null);
            }

            type.Description = description;

            var nodes = element.ChildNodes;

            for (int i = 0; i < nodes.Count; i++)
            {
                var node = nodes.Item(i);
                if (Convert.ToInt16(node.NodeType) != (short)XmlNodeType.Element)
                {
                    continue;
                }

                var nodeElement = (XmlElement)node;
                if (nodeElement.Name.Equals("ext"))
                {
                    ReadExt(nodeElement, type);
                }
                else if (nodeElement.Name.Equals("magic"))
                {
                    ReadMagic(nodeElement, type);
                }
            }

            return(type);
        }