- Remove From My Forums
Question
User-524191788 posted
hi,
Thanks for your time.
i have created a small web application with XML. It is working fine but In this XML file, i want to add html tags in one of the column, named Content. And html tags like: bold,italic,para and so....on.
I hope this is clear.
XML file is as follows:profile.xml
<
and default.aspx as follows
DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
thanks once again.
Answers
User-512755392 posted
Thanks for your infomation.
You have to decode html tag before write it to Response.
Here is my tested code[I converted from C# to VB]:
Imports System Imports System.Data Imports System.Configuration Imports System.Collections Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Xml Imports System.Xml.Xsl Imports System.Xml.XPath Imports System.IO Public Class xml_xslt_display Inherits System.Web.UI.Page Protected Sub Page_Load[ByVal sender As Object, ByVal e As EventArgs] Dim output As String = "" Dim msXml As MemoryStream = New MemoryStream Dim writer As XmlTextWriter = New XmlTextWriter[msXml, System.Text.Encoding.UTF8] Try Response.Clear Dim xml_p As String = "test57.xml" Dim xslt_p As String = "xslt57.xsl" Dim xmlPath As String = Server.MapPath[xml_p] Dim xslPath As String = Server.MapPath[xslt_p] 'Instantiate the XPathDocument Class Dim doc As XPathDocument = New XPathDocument[xmlPath] 'Instantiate the XslTransform Class Dim transform As XslCompiledTransform = New XslCompiledTransform transform.Load[xslPath] transform.Transform[doc, Nothing, writer] msXml.Position = 0 Dim xmlReader As XmlReader = XmlReader.Create[msXml] While xmlReader.Read output = xmlReader.ReadOuterXml End While Response.Write[Server.HtmlDecode[output]] Response.End xmlReader.Close Finally msXml.Close writer.Flush writer.Close End Try End Sub End Class
I transform xml with xslt manually instead of using XML Control.
- Marked as answer by Thursday, October 7, 2021 12:00 AM
User-524191788 posted
HI,
I appreciate your work, thanks.
I've got another way also in very very short "one line code". I think you might be knowing this.
in XSLT file we have to add this code: where we want to add xhtml source code in element of XML file.
I hope it is clear.
Thank you All
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM