On my .aspx page, I have a value that I retrieve in my CultureDependent.resx-file.
my XML element looks like:
<data name="BannerTextMain" xml:space="preserve">
<value>Test String,
<![CDATA[<html><body>
link!</body></html>
]]>
</value>
</data>
The problem is, is that my href isn't working : literal text is shown.
I was wondering if this was normal?
If i leave the CDATA section out of it, my text isn't shown at all.
how can i include a href in my text?
Related
I have an HTML string in my code behind which has some valid html tags such as <br/>, <p></p>, and some invalid tags such as <test>. I want to render both sets of tags in the browser in such a way that invalid tags are rendered as plain text.
For example, the string
<test><br/>hi mark.<br/>how are you.My email is <test#test.com>
would to need to output on the browser as
<test>
hi mark.how are you.My email is <test#test.com>
You would need to whitelist the elements you consider to be valid, and then encode those which do not match the whitelist so that they are instead converted to <test> as opposed to <test>. The ampersand values will render as < text on the page.
I have problem with parsing my HTML code from XML
Here some code for introducing
<item>
<title>
My HTML code
</title>
<description>
<![CDATA[Here some example
<ul style="list-style: disc;" type="disc">
<li>Text1</li>
<li>Text2</li>
</ul>]]>
</description>
</item>
I'd like show this code in 2 ways, first like html list and second like string(make visible all tags e.g...)
I tried to grab this code in 2 ways and in booth result are same
string DescriptionCurent = item.Element("description").Value.ToString();
HtmlString html2 = new HtmlString(item.Element("description").Value.ToString());
And on the end I show this on page
<p><%= DescriptionCurent %></p>
<p><%: html2 %></p>
On the end we have text before in p tag, and list outside P tag showing like regular list.
I use asp.net 4.5 web forms
If you can't understand something pls ask and I will try to explain better
UPDATE:
I cant add images because i need 10 reputation so i put it on some free host
Here is image ho that look
http://tinypic.com/view.php?pic=2eam7bb&s=8#.VQLYLY7F91A
And here it's in inspect element how look
http://tinypic.com/view.php?pic=zv205h&s=8
so I just need to add everything in tag no outside
I assume that item is an XElement from LINQ-to-XML. So, to get XML markup from an XElement object you simply call ToString() on the object (not on the object's Value property) :
HtmlString html2 = new HtmlString(item.Element("description").ToString());
Or a different way if you meant to get, specifically, the content of the CDATA element (excluding the <CDATA> tag itself) :
XCData cdata = (XCData)item.Element("description").FirstNode;
HtmlString html2 = new HtmlString(cdata.Value);
I have my XML as a string and need to display it in a div
I have searched all the ways to format an XML, but it doesn't work as I am finally binding my contents to a div.
Following is what I am using in my asp.net applicaion c# code.
request = //my xml string
XDocument doc = XDocument.Parse(request);
divLogResults.InnerText = doc.ToString()
I have tried all the ways listed here as well
What is the simplest way to get indented XML with line breaks from XmlDocument?
So this isn't a duplicate. How can I do this in a simple way ?
Bind your XML content in a text area. I think this should work.
Web form:
<textarea rows="20" cols="40" style="border:none;" runat="server" id="txtXML" readonly="true">
</textarea>
Code behind:
request = // xml string
XDocument doc = XDocument.Parse(request);
txtXML.Text = doc.ToString()
Please make sure your xml content has the header appended
e.g.,
<?xml version="1.0" encoding="ISO-8859-1"?>
I have a xml document like below and I need to render it into HTML page. When I browse the XML from IE the HTML is rendered as expected with styling. If I load the xml document from c# code and pass to HTML page it just renders as plain text. What am I missing here?
XML
<?xml-stylesheet type='text/xsl' href='xslsheet.xsl'?>
<Document xmlns="org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
....
</Document>
C#
XDocument doc = XDocument.Load(#"C\SampleDocument.xml");
var result = doc.ToString();
Loading an XML document does just that - it loads the data. It won't process a transform directive.
To do that you need to do an XSLT Transform. You can find the classes to do that on MSDN.
I am working on a page that inherits a Base Page. The aspx page includes a control that uses xslt for to transform an xml document to html markup. Within that document I am using the following:
<xsl:template match="Headline">
<h1 runat="server" id="h1" class="article-heading">
<xsl:value-of select="text()"/>
</h1>
</xsl:template>
I am trying to get the get the value of the h1 to set it to page.title, can this be done with page.findControl ?
XSLT within a browser tends to be interpreted on the client-side, not the server side. Using Page.FindControl to find the content of the H1 won't get you too far, as all that will return is the literal <xsl:value-of...> statement.
The best approach is to also open the XML document within the codebehind on the server and set the Page Title from there.
you can use javascript to find h1 on clientside then set it to the document.title
Unfortunately no, because your <h1> element never gets added to control tree on the server. Even though you have runat="server" ASP.NET doesn't parse HTML resulting from XSLT transformation.
You would have to resort to parsing your XML to get the heading. With XPath it should be easy.