Exemplo n.º 1
0
        public void TestInvalidXml()
        {
            string doc = @"<html>
                <head><title>required</title></head>
                <body></other>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation();

            v.Validate(new StringReader(doc));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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()));
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        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()));
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        public void TestInvalidXml()
        {
            string doc = @"<html>
                <head><title>required</title></head>
                <body></other>
            </html>
            ";

            XhtmlValidation v = new XhtmlValidation();
            v.Validate(new StringReader(doc));
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 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;
        }
Exemplo n.º 18
0
        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));
        }