How to convert HTML into XML (format) in ASP.NET and in C#?

How to convert HTML into XML (format) in ASP.NET and in C#?

How to save HTML code as xml string in database/sql server using asp.net and C#?



The HTML code can be formatted into XML to save the html text into the database as xml string by using SgmlReader which is a third party library.

Download the SgmlReader and refer into your project.

//Creating the object of SgmlReader.
Sgml.SgmlReader reader = new Sgml.SgmlReader();
            reader.DocType = string.Empty;
            reader.InputStream = new StringReader(“<html code>”);
            StringWriter output = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(output);
            reader.Read();
            while (!reader.EOF)
            {
                writer.WriteNode(reader, true);
            }
            writer.Close();
            string xmlcode = output.ToString();

            xmlcode = xmlcode.Replace("&amp;", "&");
            xmlcode = xmlcode.Replace("&nbsp;", "&#160;");

            return xmlcode;

No comments:

Post a Comment