Reputation: 2144
i have the following code in my simple xml document
<?xml version="1.0"?>
<sample>
<link xml:link="simple" href="http://www.google.com"> Google page </link>
</sample>
But this is appearing as just tags in the browser irrespective of what browser it is
This is what displayed on my browser:
<sample><link xml:link="simple" href="http://www.google.com"> Google page </link></sample>
Please let me know why the hyperlink is not appearing on the browser instead of the tags. I have attempted many options but it seems like im missing something very basic here Thanks
Upvotes: 1
Views: 4675
Reputation: 1583
You can not not open XML file with HTML kind of behavior. For that you need to transform your XML file to HTML file using XSLT. Following code snap will help you to transform XML file to HTML file using XSLT:
Apply following XSLT:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Sample HTML</TITLE>
</HEAD>
<BODY>
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="sample/link">
<A TARGET="_blank">
<xsl:attribute name="HREF">
<xsl:value-of select="@href"/>
</xsl:attribute>
<xsl:apply-templates/>
</A>
</xsl:template>
XML file is this:
<sample>
<link xml:link="simple" href="http://www.google.com"> Google page </link>
</sample>
C# function to transform XML file to .HTML file is:
public void transformToHtml()
{
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load("html.xslt");
transform.Transform("htmlArtical.xml", "toHTML.html");
}
And the output .HTML file is like this:
<HTML xmlns="http://www.w3.org/TR/REC-html40">
<HEAD>
<TITLE>Sample HTML</TITLE>
</HEAD>
<BODY>
<A TARGET="_blank" HREF="http://www.google.com"> Google page </A>
</BODY>
</HTML>
Open this .HTML file in browser and you will get the link on "Google page" text.
I hope this will help you.
Upvotes: 1