Item() public method

public Item ( int index ) : XmlNode
index int
return XmlNode
Esempio n. 1
0
 /// <summary>Read Element named magic. </summary>
 private void  ReadMagic(System.Xml.XmlElement element, MimeType mimeType)
 {
     // element.getValue();
     System.String offset             = null;
     System.String content            = null;
     System.String type               = null;
     System.Xml.XmlNamedNodeMap attrs = (System.Xml.XmlAttributeCollection)element.Attributes;
     for (int i = 0; i < attrs.Count; i++)
     {
         System.Xml.XmlAttribute attr = (System.Xml.XmlAttribute)attrs.Item(i);
         if (attr.Name.Equals("offset"))
         {
             offset = attr.Value;
         }
         else if (attr.Name.Equals("type"))
         {
             type = attr.Value;
             if (String.Compare(type, "byte", true) == 0)
             {
                 type = "System.Byte";
             }
         }
         else if (attr.Name.Equals("value"))
         {
             content = attr.Value;
         }
     }
     if ((offset != null) && (content != null))
     {
         mimeType.AddMagic(System.Int32.Parse(offset), type, content);
     }
 }
        /// <summary>Removes attributes, comments, and processing instructions. </summary>
        private static void  clean(System.Xml.XmlElement elem)
        {
            System.Xml.XmlNodeList children = elem.ChildNodes;
            for (int i = 0; i < children.Count; i++)
            {
                System.Xml.XmlNode child = children.Item(i);
                if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.ProcessingInstruction || System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Comment)
                {
                    elem.RemoveChild(child);
                }
                else if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Element)
                {
                    clean((System.Xml.XmlElement)child);
                }
            }

            System.Xml.XmlNamedNodeMap attributes = (System.Xml.XmlAttributeCollection)elem.Attributes;
            //get names
            System.String[] names = new System.String[attributes.Count];
            for (int i = 0; i < names.Length; i++)
            {
                names[i] = attributes.Item(i).Name;
            }
            //remove by name
            for (int i = 0; i < names.Length; i++)
            {
                attributes.RemoveNamedItem(names[i]);
            }
        }
Esempio n. 3
0
        /// <summary>Read Element named mime-type. </summary>
        private MimeType ReadMimeType(System.Xml.XmlElement element)
        {
            System.String name        = null;
            System.String description = null;
            MimeType      type        = null;

            System.Xml.XmlNamedNodeMap attrs = (System.Xml.XmlAttributeCollection)element.Attributes;
            for (int i = 0; i < attrs.Count; i++)
            {
                System.Xml.XmlAttribute attr = (System.Xml.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.ToString() + " ... Ignoring!");
                return(null);
            }

            type.Description = description;

            System.Xml.XmlNodeList nodes = element.ChildNodes;
            for (int i = 0; i < nodes.Count; i++)
            {
                System.Xml.XmlNode node = nodes.Item(i);
                if (System.Convert.ToInt16(node.NodeType) == (short)System.Xml.XmlNodeType.Element)
                {
                    System.Xml.XmlElement nodeElement = (System.Xml.XmlElement)node;
                    if (nodeElement.Name.Equals("ext"))
                    {
                        ReadExt(nodeElement, type);
                    }
                    else if (nodeElement.Name.Equals("magic"))
                    {
                        ReadMagic(nodeElement, type);
                    }
                }
            }
            return(type);
        }