Пример #1
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="publicId"></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 publicId,
                                    string url, string subset, string proxy, XmlNameTable nt)
        {
            SgmlDtd dtd = new SgmlDtd(name, nt);

            if (!String.IsNullOrEmpty(url))
            {
                dtd.PushEntity(baseUri, new Entity(dtd.Name, publicId, 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);
        }
Пример #2
0
 public bool CanContain(string name, SgmlDtd dtd)
 {
     if (_declaredContent != DeclaredContent.Default)
         return false;
     
     return _model.CanContain(name, dtd);
 }
Пример #3
0
        public bool CanContain(string name, SgmlDtd dtd)
        {
            if (_declaredContent != DeclaredContent.Default)
            {
                return(false);
            }

            return(_model.CanContain(name, dtd));
        }
Пример #4
0
        public bool CanContain(string name, SgmlDtd dtd)
        {
            Precondition.Require(dtd, () => Error.ArgumentNull("dtd"));

            // Do a simple search of members.
            foreach (object obj in _members)
            {
                if (obj is String)
                {
                    if (String.Equals((string)obj, name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        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)
                {
                    ElementDeclaration e = dtd.FindElement(s);
                    if (e != null)
                    {
                        if (e.StartTagOptional)
                        {
                            if (e.CanContain(name, dtd))
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    Group m = (Group)obj;
                    if (m.CanContain(name, dtd))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
 public bool CanContain(string name, SgmlDtd dtd)
 {
     if (_exclusions != null)
     {
         foreach (string excl in _exclusions)
         {
             if (excl == name)
             {
                 return(false);
             }
         }
     }
     if (_inclusions != null)
     {
         foreach (string incl in _inclusions)
         {
             if (incl == name)
             {
                 return(true);
             }
         }
     }
     return(_contentModel.CanContain(name, dtd));
 }
 public bool CanContain(string name, SgmlDtd dtd)
 {
     if (_exclusions != null)
     {
         foreach (string excl in _exclusions)
         {
             if (excl == name)
                 return false;
         }
     }
     if (_inclusions != null)
     {
         foreach (string incl in _inclusions)
         {
             if (incl == name)
                 return true;
         }
     }
     return _contentModel.CanContain(name, dtd);
 }
Пример #7
0
        private void LazyLoadDtd(Uri baseUri)
        {
            if (_dtd == null)
            {
                if (String.IsNullOrEmpty(_systemLiteral))
                {
                    if (_docType != null && String.Equals(_docType, "html", 
                        StringComparison.InvariantCultureIgnoreCase))
                    {
                        Assembly a = typeof(SgmlReader).Assembly;
                        string name = a.FullName.Split(',')[0] + ".Resources.html.dtd";
                        Stream stream = a.GetManifestResourceStream(name);

                        if (stream != null)
                        {
                            StreamReader sr = new StreamReader(stream);
                            _dtd = SgmlDtd.Parse(baseUri, "HTML", sr, null, _proxy, null);
                        }
                    }
                }
                else
                {
                    if (baseUri != null)
                        baseUri = new Uri(baseUri, _systemLiteral);
                    else
                        baseUri = new Uri(new Uri(Directory.GetCurrentDirectory() + "\\"), _systemLiteral);

                    _dtd = SgmlDtd.Parse(baseUri, _docType, _publicId, baseUri.AbsoluteUri, _subset, _proxy, null);
                }
            }

            if (_dtd != null && _dtd.Name != null)
            {
                switch (CaseFolding)
                {
                    case CaseFolding.ToUpper:
                        _rootElementName = _dtd.Name.ToUpper(CultureInfo.InvariantCulture);
                        break;
                    case CaseFolding.ToLower:
                        _rootElementName = _dtd.Name.ToLower(CultureInfo.InvariantCulture);
                        break;
                    default:
                        _rootElementName = _dtd.Name;
                        break;
                }

                _isHtml = String.Equals(_dtd.Name, "html", 
                    StringComparison.InvariantCultureIgnoreCase);
            }
        }
Пример #8
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="publicId"></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 publicId, 
            string url, string subset, string proxy, XmlNameTable nt)
        {
            SgmlDtd dtd = new SgmlDtd(name, nt);
            if (!String.IsNullOrEmpty(url))
                dtd.PushEntity(baseUri, new Entity(dtd.Name, publicId, 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;
        }
Пример #9
0
        public bool CanContain(string name, SgmlDtd dtd)
        {
            Precondition.Require(dtd, () => Error.ArgumentNull("dtd"));

            // Do a simple search of members.
            foreach (object obj in _members)
            {
                if (obj is String)
                {
                    if (String.Equals((string)obj, name, StringComparison.InvariantCultureIgnoreCase))
                        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)
                {
                    ElementDeclaration e = dtd.FindElement(s);
                    if (e != null)
                    {
                        if (e.StartTagOptional)
                        {                            
                            if (e.CanContain(name, dtd))
                                return true;
                        }
                    }
                }
                else
                {
                    Group m = (Group)obj;
                    if (m.CanContain(name, dtd))
                        return true;
                }
            }
            return false;
        }