示例#1
0
        /// <summary>
        /// Tests whether this element can contain another specified element.
        /// </summary>
        /// <param name="name">The name of the element to check for.</param>
        /// <param name="dtd">The DTD to use to do the check.</param>
        /// <returns>True if the specified element can be contained by this element.</returns>
        public bool CanContain(string name, SgmlDtd dtd)
        {
            if (_exclusions.ContainsIgnoreCase(name))
            {
                return(false);
            }

            return(_inclusions.ContainsIgnoreCase(name) || ContentModel.CanContain(name, dtd));
        }
示例#2
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.
            if (_members.OfType <string>().Any(s => s.Equals(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 (var obj in _members)
            {
                var s = obj as string;
                if (s != null)
                {
                    var 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
                {
                    var m = (Group)obj;
                    if (m.CanContain(name, dtd))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#3
0
        public static SgmlDtd Parse(Uri baseUri, string name, TextReader input, string subset, string proxy, XmlNameTable nt)
        {
            var dtd = new SgmlDtd(name, nt);

            dtd.PushEntity(baseUri, new Entity(dtd.Name, baseUri, input, proxy));

            if (!string.IsNullOrEmpty(subset))
            {
                dtd.PushEntity(baseUri, new Entity(name, subset));
            }

            try {
                dtd.Parse();
            }
            catch (ApplicationException e) {
                throw new SgmlParseException(e.Message + dtd._current.Context());
            }

            return(dtd);
        }
示例#4
0
        private void SetHtmlDtd( Uri baseUri )
        {
            var assembly = typeof( SgmlReader ).Assembly;
              var name = assembly.FullName.Split( ',' )[ 0 ] + ".Html.dtd";
              var stream = assembly.GetManifestResourceStream( name );

              if( stream == null ) return;

              var reader = new StreamReader( stream );
              _dtd = SgmlDtd.Parse( baseUri, "HTML", reader, null, _proxy, null );
        }
示例#5
0
        private void SetDtd( Uri baseUri )
        {
            if( _dtd != null || _ignoreDtd ) return;

              if( string.IsNullOrEmpty( _systemLiteral ) ) {
            if( _docType != null && _docType.EqualsIgnoreCase( "html" ) ) {
              SetHtmlDtd( baseUri );
            }
              }
              else {
            if( baseUri != null ) {
              baseUri = new Uri( baseUri, _systemLiteral );
            }
            else if( _baseUri != null ) {
              baseUri = new Uri( _baseUri, _systemLiteral );
            }
            else {
              baseUri = new Uri( new Uri( Directory.GetCurrentDirectory() + "\\" ), _systemLiteral );
            }
            _dtd = SgmlDtd.Parse( baseUri, _docType, _publicIdentifier, baseUri.AbsoluteUri, _subset, _proxy, null );
              }
        }
示例#6
0
        /// <summary>
        /// Parses a DTD and creates a <see cref="SgmlDtd"/> instance that encapsulates the DTD.
        /// </summary>
        /// <param name="baseUri">The base URI of the DTD.</param>
        /// <param name="name">The name of the DTD.</param>
        /// <param name="pubid"></param>
        /// <param name="url"></param>
        /// <param name="subset"></param>
        /// <param name="proxy"></param>
        /// <param name="nt">The <see cref="XmlNameTable"/> is NOT used.</param>
        /// <returns>A new <see cref="SgmlDtd"/> instance that encapsulates the DTD.</returns>
        public static SgmlDtd Parse( Uri baseUri, string name, string pubid, string url, string subset, string proxy, XmlNameTable nt )
        {
            var dtd = new SgmlDtd( name, nt );
              if( !string.IsNullOrEmpty( url ) ) {
            dtd.PushEntity( baseUri, new Entity( dtd.Name, pubid, url, proxy ) );
              }

              if( !string.IsNullOrEmpty( subset ) ) {
            dtd.PushEntity( baseUri, new Entity( name, subset ) );
              }

              try {
            dtd.Parse();
              }
              catch( ApplicationException e ) {
            throw new SgmlParseException( e.Message + dtd._current.Context() );
              }

              return dtd;
        }
示例#7
0
        /// <summary>
        /// Tests whether this element can contain another specified element.
        /// </summary>
        /// <param name="name">The name of the element to check for.</param>
        /// <param name="dtd">The DTD to use to do the check.</param>
        /// <returns>True if the specified element can be contained by this element.</returns>
        public bool CanContain( string name, SgmlDtd dtd )
        {
            if( _exclusions.ContainsIgnoreCase( name ) ) return false;

              return _inclusions.ContainsIgnoreCase( name ) || ContentModel.CanContain( name, dtd );
        }
示例#8
0
文件: Group.cs 项目: nrkn/SGMLReader
        /// <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.
              if( _members.OfType<string>().Any( s => s.Equals( 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( var obj in _members ) {
            var s = obj as string;
            if( s != null ) {
              var 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 {
              var m = (Group) obj;
              if( m.CanContain( name, dtd ) )
            return true;
            }
              }

              return false;
        }
示例#9
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>
 public bool CanContain(string name, SgmlDtd dtd)
 {
     return(DeclaredContent == DeclaredContent.Default && _model.CanContain(name, dtd));
 }
示例#10
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>
 public bool CanContain( string name, SgmlDtd dtd )
 {
     return DeclaredContent == DeclaredContent.Default && _model.CanContain( name, dtd );
 }