public void TestInvalidXml()
        {
            string doc = @"<html>
                <head><title>required</title></head>
                <body></other>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation();

            v.Validate(new StringReader(doc));
        }
        public void TestValidNoDTD()
        {
            string doc = @"<html>
                <head><title>required</title></head>
                <body></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.None);

            v.Validate(new StringReader(doc));
        }
        public void TestValidFrameset()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Frameset//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"">
            <html>
                <head><title>required</title></head>
                <frameset></frameset>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.XhtmlFrameset_10);
            v.Validate(new StringReader(doc));
        }
        public void TestInvalidRoot()
        {
            string doc = @"<!DOCTYPE abc PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <abc>
                <head><title>required</title></head>
                <body><iframe></iframe></body>
            </abc>
            ";

            XhtmlValidation v = new XhtmlValidation();

            v.Validate(new StringReader(doc));
        }
        public void TestInvalidAttribute()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <html>
                <head><title>required</title></head>
                <body width=100></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation();

            v.Validate(new StringReader(doc));
        }
        public void TestInvalidDTD()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//Some DTD Specification//EN"" ""http://www.w3.org/something.dtd"">
            <html>
                <head><title>required</title></head>
                <body></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.None);

            v.Validate(new StringReader(doc));
        }
        public void TestValidAnyDTD()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Frameset//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"">
            <html>
                <head><title>required</title></head>
                <frameset></frameset>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.Any);

            v.Validate(new StringReader(doc));
        }
        public void TestValidTransitional()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
            <html>
                <head><title>required</title></head>
                <body><iframe></iframe></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.XhtmlTransitional_10);

            using (TempFile temp = new TempFile())
            {
                temp.WriteAllText(doc);
                v.Validate(@"C:\transitional.xhtml", new StreamReader(temp.Read()));
            }
        }
        public void TestValidStrict()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <html>
                <head><title>required</title></head>
                <body></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.XhtmlStrict_10);

            using (TempFile temp = new TempFile())
            {
                temp.WriteAllText(doc);
                v.Validate(temp.TempPath);
            }
        }
        public void TestValidTransitional()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
            <html>
                <head><title>required</title></head>
                <body><iframe></iframe></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.XhtmlTransitional_10);

            using (TempFile temp = new TempFile())
            {
                temp.WriteAllText(doc);
                v.Validate(@"C:\transitional.xhtml", new StreamReader(temp.Read()));
            }
        }
        public void TestValidStrict()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <html>
                <head><title>required</title></head>
                <body></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.XhtmlStrict_10);

            using (TempFile temp = new TempFile())
            {
                temp.WriteAllText(doc);
                v.Validate(temp.TempPath);
            }
        }
        public void TestInvalidXml()
        {
            string doc = @"<html>
                <head><title>required</title></head>
                <body></other>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation();
            v.Validate(new StringReader(doc));
        }
Beispiel #13
0
        static int Main(string[] raw)
        {
            ArgumentList args = new ArgumentList(raw);

            using (DisposingList dispose = new DisposingList())
                using (Log.AppStart(Environment.CommandLine))
                {
                    if (args.Contains("nologo") == false)
                    {
                        Console.WriteLine("XhtmlValidate.exe");
                        Console.WriteLine("Copyright 2010 by Roger Knapp, Licensed under the Apache License, Version 2.0");
                        Console.WriteLine("");
                    }

                    if ((args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help"))
                    {
                        return(DoHelp());
                    }

                    try
                    {
                        FileList files = new FileList();
                        files.RecurseFolders = true;
                        foreach (string spec in args.Unnamed)
                        {
                            Uri uri;
                            if (Uri.TryCreate(spec, UriKind.Absolute, out uri) && !(uri.IsFile || uri.IsUnc))
                            {
                                using (WebClient wc = new WebClient())
                                {
                                    TempFile tfile = new TempFile();
                                    dispose.Add(tfile);
                                    wc.DownloadFile(uri, tfile.TempPath);
                                    files.Add(tfile.Info);
                                }
                            }
                            else
                            {
                                files.Add(spec);
                            }
                        }
                        if (files.Count == 0)
                        {
                            return(1 + DoHelp());
                        }

                        XhtmlValidation validator = new XhtmlValidation(XhtmlDTDSpecification.Any);
                        foreach (FileInfo f in files)
                        {
                            validator.Validate(f.FullName);
                        }
                    }
                    catch (ApplicationException ae)
                    {
                        Log.Error(ae);
                        Console.Error.WriteLine();
                        Console.Error.WriteLine(ae.Message);
                        Environment.ExitCode = -1;
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                        Console.Error.WriteLine();
                        Console.Error.WriteLine(e.ToString());
                        Environment.ExitCode = -1;
                    }
                }

            if (args.Contains("wait"))
            {
                Console.WriteLine();
                Console.WriteLine("Press [Enter] to continue...");
                Console.ReadLine();
            }

            return(Environment.ExitCode);
        }
        public void TestValidNoDTD()
        {
            string doc = @"<html>
                <head><title>required</title></head>
                <body></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.None);
            v.Validate(new StringReader(doc));
        }
        public void TestInvalidRoot()
        {
            string doc = @"<!DOCTYPE abc PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <abc>
                <head><title>required</title></head>
                <body><iframe></iframe></body>
            </abc>
            ";

            XhtmlValidation v = new XhtmlValidation();
            v.Validate(new StringReader(doc));
        }
        public void TestInvalidAttribute()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
            <html>
                <head><title>required</title></head>
                <body width=100></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation();
            v.Validate(new StringReader(doc));
        }
Beispiel #17
0
        static int Main(string[] raw)
        {
            ArgumentList args = new ArgumentList(raw);

            using (DisposingList dispose = new DisposingList())
            using (Log.AppStart(Environment.CommandLine))
            {
                if (args.Contains("nologo") == false)
                {
                    Console.WriteLine("XhtmlValidate.exe");
                    Console.WriteLine("Copyright 2010 by Roger Knapp, Licensed under the Apache License, Version 2.0");
                    Console.WriteLine("");
                }

                if ((args.Unnamed.Count == 0) || args.Contains("?") || args.Contains("help"))
                    return DoHelp();

                try
                {
                    FileList files = new FileList();
                    files.RecurseFolders = true;
                    foreach (string spec in args.Unnamed)
                    {
                        Uri uri;
                        if (Uri.TryCreate(spec, UriKind.Absolute, out uri) && !(uri.IsFile || uri.IsUnc))
                        {
                            using(WebClient wc = new WebClient())
                            {
                                TempFile tfile = new TempFile();
                                dispose.Add(tfile);
                                wc.DownloadFile(uri, tfile.TempPath);
                                files.Add(tfile.Info);
                            }
                        }
                        else
                            files.Add(spec);
                    }
                    if( files.Count == 0 )
                        return 1 + DoHelp();

                    XhtmlValidation validator = new XhtmlValidation(XhtmlDTDSpecification.Any);
                    foreach (FileInfo f in files)
                        validator.Validate(f.FullName);
                }
                catch (ApplicationException ae)
                {
                    Log.Error(ae);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(ae.Message);
                    Environment.ExitCode = -1;
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(e.ToString());
                    Environment.ExitCode = -1;
                }
            }

            if (args.Contains("wait"))
            {
                Console.WriteLine();
                Console.WriteLine("Press [Enter] to continue...");
                Console.ReadLine();
            }

            return Environment.ExitCode;
        }
        public void TestInvalidDTD()
        {
            string doc = @"<!DOCTYPE html PUBLIC ""-//Some DTD Specification//EN"" ""http://www.w3.org/something.dtd"">
            <html>
                <head><title>required</title></head>
                <body></body>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation(XhtmlDTDSpecification.None);
            v.Validate(new StringReader(doc));
        }