Esempio n. 1
0
 /// <summary> Creates a validator that requires documents to use the specified DTD </summary>
 public XhtmlValidation(XhtmlDTDSpecification dtdRequired)
 {
     _requiresDtd = dtdRequired;
     _nameTable   = new NameTable();
     _namespaces  = new XmlNamespaceManager(_nameTable);
     _namespaces.AddNamespace("htm", "http://www.w3.org/1999/xhtml");
 }
Esempio n. 2
0
        void ValidateDocument(XhtmlDTDSpecification expect, string filename, string contents)
        {
            XmlResolver resolver = new XmlResolver();

            resolver.Credentials = null;
            ValidationErrorsList errors = new ValidationErrorsList(filename, contents);

            using (XmlReader reader = XmlReader.Create(new StringReader(contents), MakeReaderSettings(resolver, errors.OnValidationError)))
            {
                try
                {
                    reader.MoveToContent();

                    if (expect != XhtmlDTDSpecification.None)
                    {
                        if (expect != XhtmlDTDSpecification.Any && expect != resolver.DTDSpecification)
                        {
                            throw new XmlException("Missing required DTD specification.", null, 1, 1);
                        }

                        if (reader.LocalName != "html")
                        {
                            throw new XmlException(String.Format("Unexpected root element: {0}", reader.LocalName));
                        }
                        if (reader.NamespaceURI != _namespaces.LookupNamespace("htm"))
                        {
                            throw new XmlException(String.Format("Unexpected root namespace: {0}", reader.NamespaceURI));
                        }
                    }
                    while (reader.Read())
                    {
                    }
                }
                catch (XmlException xmlEx)
                {
                    errors.OnXmlException(xmlEx);
                }
            }

            errors.Assert();
        }
Esempio n. 3
0
            public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
            {
                Uri    cwd = new Uri(Environment.CurrentDirectory);
                string loc = absoluteUri.ToString();

                if (loc.StartsWith(cwd.AbsoluteUri))
                {
                    loc = loc.Substring(cwd.AbsoluteUri.Length).TrimStart('/');
                }

                foreach (DOCTYPEAttribute attr in _docTypes)
                {
                    if (attr.PUBLIC == loc || attr.SYSTEM == loc)
                    {
                        this.DTDSpecification = attr.DTD;
                        return(Check.NotNull(GetType().Assembly.GetManifestResourceStream(GetType(), attr.RESOURCE)));
                    }
                }

                if (this.DTDSpecification == XhtmlDTDSpecification.XhtmlStrict_10 ||
                    this.DTDSpecification == XhtmlDTDSpecification.XhtmlFrameset_10 ||
                    this.DTDSpecification == XhtmlDTDSpecification.XhtmlTransitional_10)
                {
                    if (loc.EndsWith("/xhtml-lat1.ent"))
                    {
                        return(Check.NotNull(GetType().Assembly.GetManifestResourceStream(GetType(), "Xhtml1_0.xhtml-lat1.ent")));
                    }
                    else if (loc.EndsWith("/xhtml-special.ent"))
                    {
                        return(Check.NotNull(GetType().Assembly.GetManifestResourceStream(GetType(), "Xhtml1_0.xhtml-special.ent")));
                    }
                    else if (loc.EndsWith("/xhtml-symbol.ent"))
                    {
                        return(Check.NotNull(GetType().Assembly.GetManifestResourceStream(GetType(), "Xhtml1_0.xhtml-symbol.ent")));
                    }
                }

                return(null);
            }