Click here to Skip to main content
15,892,809 members
Articles / Programming Languages / XML

Converting an HTML File to an XHTML File

Rate me:
Please Sign up or sign in to vote.
2.47/5 (5 votes)
19 Mar 20073 min read 75.2K   984   22  
Converting a HTML file to an XHTML file
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;
using ChinaCars.Util.App_GlobalResources;

namespace ChinaCars.Util
{
    public class XHTMLResolver:XmlResolver
    {
        override public ICredentials Credentials
        {
            set {  }
        }

        public XHTMLResolver()
        {
            
        }

        public override Uri ResolveUri(Uri baseUri, String relativeUri)
        {
            if (String.Compare(relativeUri, "-//W3C//DTD XHTML 1.0 Transitional//EN", true) == 0)
            {
                return new Uri("http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd");
            }
            else if (String.Compare(relativeUri, "-//W3C//DTD XHTML 1.0 Transitional//EN", true) == 0)
            {
                return new Uri("http://www.w3.org/tr/xhtml1/DTD/xhtml1-strict.dtd");
            }
            else if (String.Compare(relativeUri, "-//W3C//DTD XHTML 1.0 Transitional//EN", true) == 0)
            {
                return new Uri("http://www.w3.org/tr/xhtml1/DTD/xhtml1-frameset.dtd");
            }
            else if (String.Compare(relativeUri, "-//W3C//DTD XHTML 1.1//EN", true) == 0)
            {
                return new Uri("http://www.w3.org/tr/xhtml11/DTD/xhtml11.dtd");
            }

            return base.ResolveUri(baseUri,relativeUri);
        }
        override public object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
        {
            Object entityObj = null;
            String strURI = absoluteUri.AbsoluteUri;
            System.IO.MemoryStream msStream=null;


            switch (strURI.ToLower())
            {
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd":
                    msStream = new MemoryStream(Resource.xhtml1_transitional);
                    break;
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml1.dcl":
                    msStream = new MemoryStream(Resource.xhtml1);
                    break;
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml-lat1.ent":
                    msStream = new MemoryStream(Resource.xhtml_lat1);
                    break;
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml-special.ent":
                    msStream = new MemoryStream(Resource.xhtml_special);
                    break;
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml-symbol.ent":
                    msStream = new MemoryStream(Resource.xhtml_symbol);
                    break;
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd":
                    msStream = new MemoryStream(Resource.xhtml1_strict);
                    break;
                case "http://www.w3.org/tr/xhtml1/dtd/xhtml1-frameset.dtd":
                    msStream = new MemoryStream(Resource.xhtml1_frameset);
                    break;
                case "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd":
                    msStream = new MemoryStream(Resource.xhtml11);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-inlstyle-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_inlstyle_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-framework-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_framework_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-datatypes-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_datatypes_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-qname-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_qname_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-events-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_events_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-attribs-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_attribs_1);
                    break;
                case "http://www.w3.org/tr/xhtml11/dtd/xhtml11-model-1.mod":
                    msStream = new MemoryStream(Resource.xhtml11_model_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-charent-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_charent_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-lat1.ent":
                    msStream = new MemoryStream(Resource.xhtml_lat11);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-symbol.ent":
                    msStream = new MemoryStream(Resource.xhtml_symbol11);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-special.ent":
                    msStream = new MemoryStream(Resource.xhtml_special11);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-text-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_text_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-inlstruct-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_inlstruct_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-inlphras-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_inlphras_1);
                    break;
                case "http://www.w3.org/tr/ruby/xhtml-ruby-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_ruby_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-blkstruct-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_blkstruct_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-blkphras-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_blkphras_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-hypertext-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_hypertext_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-list-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_list_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-edit-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_edit_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-bdo-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_bdo_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-pres-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_pres_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-inlpres-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_inlpres_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-blkpres-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_blkpres_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-link-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_link_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-meta-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_meta_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-base-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_base_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-script-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_script_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-style-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_style_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-image-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_image_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-csismap-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_csismap_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-ssismap-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_ssismap_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-param-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_param_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-object-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_object_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-table-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_table_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-form-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_form_1);
                    break;
                case "http://www.w3.org/tr/xhtml-modularization/dtd/xhtml-struct-1.mod":
                    msStream = new MemoryStream(Resource.xhtml_struct_1);
                    break;
            }
          

            if (msStream != null)
            {
                entityObj = msStream;
            }
            else
            {
                XmlUrlResolver xur = new XmlUrlResolver();
                entityObj = xur.GetEntity(absoluteUri, role, ofObjectToReturn);
            }
            return entityObj;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Web Developer
China China
About the author:
Jinjin Xie is the technical director of ChinaCars Co.LTD, expertise in Application Architect,Performance Tunning and VLDB design.
email:jinjun@jinjun.com.
office phone:8610-64014646 ext. 779

Comments and Discussions