0

I have an XML file having elements like this

<component name="component1">
<title><![CDATA[Title <span>(Subtitle)</span>]]></title>
</component>

I want to render the title in an HTML page. I can read the title element and when I am rendering it in the HTML page(in browser) I am getting as Title<span>(Subtitle)</span> in the page. In the HTML source it is as Title&lt;span&gt;(Subtitle)&lt;/span&gt;

How can I overcome this.

I am using C# for reading the XML data

XmlDocument document = new XmlDocument();
document.Load("pathofdocument");
XmlNodeList nodes = document.DocumentElement.SelectNodes("/list/components/componet");
foreach (XmlNode node in nodes)
{
 string title = node.SelectSingleNode("title").InnerText;
}
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
geothachankary
  • 1,040
  • 1
  • 17
  • 30
  • 1
    You need to show us the code that is putting the XML data into the HTML. – Quentin Apr 28 '15 at 12:42
  • I am using C# for reading from the XML – geothachankary Apr 28 '15 at 12:45
  • You need to show us the relevant code (it would be a good idea to read http://sscce.org/ ) and not just tell us what programming language you are using. – Quentin Apr 28 '15 at 12:46
  • 1
    After your latest edit, you've shown us the code that reads the data from the XML, but not the code that generates the HTML from it. – Quentin Apr 28 '15 at 12:55
  • I will put the title in a ViewBag and put the ViewBag in the html tag. The edited code is a controller code and I will place the ViewBag from the controller in View code. Hope you understand what I am saying – geothachankary Apr 28 '15 at 12:59
  • Show how you put the string from ViewBag in the html tag then. That's closely related to why you got the string escaped, and how to fix it : [Writing/outputting HTML strings unescaped](http://stackoverflow.com/questions/4281424/writing-outputting-html-strings-unescaped) – har07 Apr 28 '15 at 13:13

1 Answers1

0

Why don't you use HttpUtility.HtmlDecode Method

Tim Morford
  • 101
  • 1
  • 11