FindElement() public method

Finds an element declaration in the DTD with the specified name.
public FindElement ( string name ) : ElementDecl
name string The name of the to find and return.
return ElementDecl
Exemplo n.º 1
0
        /// <summary>
        /// Checks whether an element using this group can contain a specified element.
        /// </summary>
        /// <param name="name">The name of the element to look for.</param>
        /// <param name="dtd">The DTD to use during the checking.</param>
        /// <returns>true if an element using this group can contain the element, otherwise false.</returns>
        /// <remarks>
        /// Rough approximation - this is really assuming an "Or" group
        /// </remarks>
        public bool CanContain(string name, SgmlDtd dtd)
        {
            if (dtd == null)
                throw new ArgumentNullException("dtd");

            // Do a simple search of members.
            foreach (object obj in Members) 
            {
                if (obj is string) 
                {
                    if( string.Equals((string)obj, name, StringComparison.OrdinalIgnoreCase))
                        return true;
                } 
            }
            // didn't find it, so do a more expensive search over child elements
            // that have optional start tags and over child groups.
            foreach (object obj in Members) 
            {
                string s = obj as string;
                if (s != null)
                {
                    ElementDecl e = dtd.FindElement(s);
                    if (e != null) 
                    {
                        if (e.StartTagOptional) 
                        {
                            // tricky case, the start tag is optional so element may be
                            // allowed inside this guy!
                            if (e.CanContain(name, dtd))
                                return true;
                        }
                    }
                } 
                else 
                {
                    Group m = (Group)obj;
                    if (m.CanContain(name, dtd)) 
                        return true;
                }
            }

            return false;
        }
Exemplo n.º 2
0
 // Rough approximation - this is really assuming an "Or" group
 public bool CanContain(string name, SgmlDtd dtd)
 {
     // Do a simple search of members.
     foreach (object obj in Members) 
     {
         if (obj is String) 
         {
             if (obj == (object)name) // XmlNameTable optimization
                 return true;
         } 
     }
     // didn't find it, so do a more expensive search over child elements
     // that have optional start tags and over child groups.
     foreach (object obj in Members) 
     {
         if (obj is String) 
         {
             string s = (string)obj;
             ElementDecl e = dtd.FindElement(s);
             if (e != null) 
             {
                 if (e.StartTagOptional) 
                 {
                     // tricky case, the start tag is optional so element may be
                     // allowed inside this guy!
                     if (e.CanContain(name, dtd))
                         return true;
                 }
             }
         } 
         else 
         {
             Group m = (Group)obj;
             if (m.CanContain(name, dtd)) 
                 return true;
         }
     }
     return false;
 }