CodersAdvocate

I work hard, so you don't have to

Coding a XHTML validator in Csharp

 

It may have come to your attention that xml is the new HTML. All the Markups nowadays need to validate, approximate, to begin the nearest thing to perfect code. This is my take on how to get DOTNET to do everything for you.

Actually its as easy as pissing on the floor with your eyes closed.
If you first write the XSD and DTDs necesary or do what I like to do and each off of another site that offers them for you to use the W3C is a good example.

Anyway, sort out your DOC Types and stick them on top of the page and hey presto, stick it in to a XMLDocument in CSHARP and boom xmlExceptions.
"no root element found on line 1 position 1" etc....
It's as beautiful as me. I love it.

Before you all run away complaining this doesn't work, there is one catch. If you host ISP or the server doesn't allow you to connect to other sites, you will need to manually connect to the web server. A complete code listing is printed below, and intelisense will do the rest for you.

            string stringBuilder = String.Empty;
            try
            {
                string ProxyIP = "123.123.123.123:80"
                string ProxyUser = "user123"
                string proxypassword = "pass123"
                WebProxy p = new WebProxy(ProxyUser, true);
                p.Credentials = new NetworkCredential(user123, proxypassword);
                GlobalProxySelection.Select = p;


                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas.Add(null, "http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd");
                
                XmlDocument xmld = new XmlDocument();
                xmld.Schemas = settings.Schemas;
                xmld.LoadXml(xhtml);
                xmld.Validate(ValidationEventHandler);
            }
            catch (Exception exc)
            {
                stringBuilder += exc.Message.ToString();
            }
            return stringBuilder;
Copyright 2011 CodersAdvocate ©