Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » Windows Forms » Diplaying XML content in the WEB BROWSER control in winform.
       
Author Reply
Siddhartha Sarkar
posted 21 posts
since Apr 08, 2008 
from

 Diplaying XML content in the WEB BROWSER control in winform.
  Posted on: 12 Dec 2008       

Hi,

I have a string variable containing xml content. I wish to show th content in the web browser control and want the display to be same as in IE.

I tried with various properties of the browser control like the document, documentStream, documentText but none could give desired results. I tried searching on net and established that I need to have the 1.0 compliant xls defaultss.xslt.
Can someone please point me to somewhere from where I can get it. From most of the places I have tried searching, either the page has vanished or the link is no more available.
Also if someone can suggest some method that can bypass the need of the xslt it will be even better.Can my problem be solved using mshtml.dll or any other dll that the VS offers?

Thanks,

Sid

Siddhartha
Ashley Argile
posted  39 posts
since  Sep 30, 2008 
from 

Re: Diplaying XML content in the WEB BROWSER control in winform.
  Posted on: 14 Dec 2008      0 0    
Siddhartha Sarkar
posted  21 posts
since  Apr 08, 2008 
from 

Re: Diplaying XML content in the WEB BROWSER control in winform.
  Posted on: 14 Dec 2008      0 0    

Ahh Ashley its again you at my rescue. The link in the page res://msxml.dll/defaultss.xsl is not working.

I have however fixed my problem with the following code:

StreamReader fs = new StreamReader(filePath);

//XML string data

string myXml = fs.ReadToEnd();

// Load the xslt used by IE to render the xml

System.Xml.Xsl.XslCompiledTransform xTrans = new System.Xml.Xsl.XslCompiledTransform();

xTrans.Load("Defaultss.xslt");

// Read the xml string data into an XML reader object

StringReader sr = new StringReader(myXml);

XmlReader xReader = XmlReader.Create(sr);

//Apply / transform the XML data

System.IO.MemoryStream ms = new MemoryStream();

xTrans.Transform(xReader, null, ms);

// Reset the position

ms.Position = 0;

// Set to the document stream

this.webMDNFileViewer.DocumentStream = ms;

I am also posting the content of the Defaultss.xslt file here. All you need to do is copy the below content, paste it in a notepad and save it as the Defaultss.xslt file in your application startup folder.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output indent="no" method="html"/>
 <xsl:template match="/">
  <HTML>
   <HEAD>
    <SCRIPT>
     <xsl:comment><![CDATA[
                  function f(e){
                     if (e.className=="ci") {
                       if (e.children(0).innerText.indexOf("\n")>0) fix(e,"cb");
                     }
                     if (e.className=="di") {
                       if (e.children(0).innerText.indexOf("\n")>0) fix(e,"db");
                     } e.id="";
                  }
                  function fix(e,cl){
                    e.className=cl;
                    e.style.display="block";
                    j=e.parentElement.children(0);
                    j.className="c";
                    k=j.children(0);
                    k.style.visibility="visible";
                    k.href="#";
                  }
                  function ch(e) {
                    mark=e.children(0).children(0);
                    if (mark.innerText=="+") {
                      mark.innerText="-";
                      for (var i=1;i<e.children.length;i++) {
                        e.children(i).style.display="block";
                      }
                    }
                    else if (mark.innerText=="-") {
                      mark.innerText="+";
                      for (var i=1;i<e.children.length;i++) {
                        e.children(i).style.display="none";
                      }
                    }
                  }
                  function ch2(e) {
                    mark=e.children(0).children(0);
                    contents=e.children(1);
                    if (mark.innerText=="+") {
                      mark.innerText="-";
                      if (contents.className=="db"||contents.className=="cb") {
                        contents.style.display="block";
                      }
                      else {
                        contents.style.display="inline";
                      }
                    }
                    else if (mark.innerText=="-") {
                      mark.innerText="+";
                      contents.style.display="none";
                    }
                  }
                  function cl() {
                    e=window.event.srcElement;
                    if (e.className!="c") {
                      e=e.parentElement;
                      if (e.className!="c") {
                        return;
                      }
                    }
                    e=e.parentElement;
                    if (e.className=="e") {
                      ch(e);
                    }
                    if (e.className=="k") {
                      ch2(e);
                    }
                  }
                  function ex(){}
                  function h(){window.status=" ";}
                  document.onclick=cl;
              ]]></xsl:comment>
    </SCRIPT>
    <STYLE>
              BODY {font:x-small 'Verdana'; margin-right:1.5em}
                .c  {cursor:hand}
                .b  {color:red; font-family:'Courier New'; font-weight:bold;
                     text-decoration:none}
                .e  {margin-left:1em; text-indent:-1em; margin-right:1em}
                .k  {margin-left:1em; text-indent:-1em; margin-right:1em}
                .t  {color:#990000}
                .xt {color:#990099}
                .ns {color:red}
                .dt {color:green}
                .m  {color:blue}
                .tx {font-weight:bold}
                .db {text-indent:0px; margin-left:1em; margin-top:0px;
                     margin-bottom:0px;padding-left:.3em;
                     border-left:1px solid #CCCCCC; font:small Courier}
                .di {font:small Courier}
                .d  {color:blue}
                .pi {color:blue}
                .cb {text-indent:0px; margin-left:1em; margin-top:0px;
                     margin-bottom:0px;padding-left:.3em; font:small Courier;
                     color:#888888}
                .ci {font:small Courier; color:#888888}
                PRE {margin:0px; display:inline}
           </STYLE>
   </HEAD>
   <BODY class="st">
    <xsl:apply-templates/>
   </BODY>
  </HTML>
 </xsl:template>
 <xsl:template match="processing-instruction()">
  <DIV class="e">
   <SPAN class="b">
    <xsl:call-template name="entity-ref">
     <xsl:with-param name="name">nbsp</xsl:with-param>
    </xsl:call-template>
   </SPAN>
   <SPAN class="m">
    <xsl:text>&lt;?</xsl:text>
   </SPAN>
   <SPAN class="pi">
    <xsl:value-of select="name(.)"/>
    <xsl:value-of select="."/>
   </SPAN>
   <SPAN class="m">
    <xsl:text>?></xsl:text>
   </SPAN>
  </DIV>
 </xsl:template>
 <xsl:template match="processing-instruction('xml')">
  <DIV class="e">
   <SPAN class="b">
    <xsl:call-template name="entity-ref">
     <xsl:with-param name="name">nbsp</xsl:with-param>
    </xsl:call-template>
   </SPAN>
   <SPAN class="m">
    <xsl:text>&lt;?</xsl:text>
   </SPAN>
   <SPAN class="pi">
    <xsl:text>xml </xsl:text>
    <xsl:for-each select="@*">
     <xsl:value-of select="name(.)"/>
     <xsl:text>="</xsl:text>
     <xsl:value-of select="."/>
     <xsl:text>" </xsl:text>
    </xsl:for-each>
   </SPAN>
   <SPAN class="m">
    <xsl:text>?></xsl:text>
   </SPAN>
  </DIV>
 </xsl:template>
 <xsl:template match="@*">
  <SPAN>
   <xsl:attribute name="class"><xsl:if test="xsl:*/@*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
   <xsl:value-of select="name(.)"/>
  </SPAN>
  <SPAN class="m">="</SPAN>
  <B>
   <xsl:value-of select="."/>
  </B>
  <SPAN class="m">"</SPAN>
 </xsl:template>
 <xsl:template match="text()">
  <DIV class="e">
   <SPAN class="b"> </SPAN>
   <SPAN class="tx">
    <xsl:value-of select="."/>
   </SPAN>
  </DIV>
 </xsl:template>
 <xsl:template match="comment()">
  <DIV class="k">
   <SPAN>
    <A STYLE="visibility:hidden" class="b" onclick="return false" onfocus="h()">-</A>
    <SPAN class="m">
     <xsl:text>&lt;!--</xsl:text>
    </SPAN>
   </SPAN>
   <SPAN class="ci" id="clean">
    <PRE>
     <xsl:value-of select="."/>
    </PRE>
   </SPAN>
   <SPAN class="b">
    <xsl:call-template name="entity-ref">
     <xsl:with-param name="name">nbsp</xsl:with-param>
    </xsl:call-template>
   </SPAN>
   <SPAN class="m">
    <xsl:text>--></xsl:text>
   </SPAN>
   <SCRIPT>f(clean);</SCRIPT>
  </DIV>
 </xsl:template>
 <xsl:template match="*">
  <DIV class="e">
   <DIV STYLE="margin-left:1em;text-indent:-2em">
    <SPAN class="b">
     <xsl:call-template name="entity-ref">
      <xsl:with-param name="name">nbsp</xsl:with-param>
     </xsl:call-template>
    </SPAN>
    <SPAN class="m">&lt;</SPAN>
    <SPAN>
     <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
     <xsl:value-of select="name(.)"/>
     <xsl:if test="@*">
      <xsl:text> </xsl:text>
     </xsl:if>
    </SPAN>
    <xsl:apply-templates select="@*"/>
    <SPAN class="m">
     <xsl:text>/></xsl:text>
    </SPAN>
   </DIV>
  </DIV>
 </xsl:template>
 <xsl:template match="*[node()]">
  <DIV class="e">
   <DIV class="c">
    <A class="b" href="#" onclick="return false" onfocus="h()">-</A>
    <SPAN class="m">&lt;</SPAN>
    <SPAN>
     <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
     <xsl:value-of select="name(.)"/>
     <xsl:if test="@*">
      <xsl:text> </xsl:text>
     </xsl:if>
    </SPAN>
    <xsl:apply-templates select="@*"/>
    <SPAN class="m">
     <xsl:text>></xsl:text>
    </SPAN>
   </DIV>
   <DIV>
    <xsl:apply-templates/>
    <DIV>
     <SPAN class="b">
      <xsl:call-template name="entity-ref">
       <xsl:with-param name="name">nbsp</xsl:with-param>
      </xsl:call-template>
     </SPAN>
     <SPAN class="m">
      <xsl:text>&lt;/</xsl:text>
     </SPAN>
     <SPAN>
      <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
      <xsl:value-of select="name(.)"/>
     </SPAN>
     <SPAN class="m">
      <xsl:text>></xsl:text>
     </SPAN>
    </DIV>
   </DIV>
  </DIV>
 </xsl:template>
 <xsl:template match="*[text() and not (comment() or processing-instruction())]">
  <DIV class="e">
   <DIV STYLE="margin-left:1em;text-indent:-2em">
    <SPAN class="b">
     <xsl:call-template name="entity-ref">
      <xsl:with-param name="name">nbsp</xsl:with-param>
     </xsl:call-template>
    </SPAN>
    <SPAN class="m">
     <xsl:text>&lt;</xsl:text>
    </SPAN>
    <SPAN>
     <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
     <xsl:value-of select="name(.)"/>
     <xsl:if test="@*">
      <xsl:text> </xsl:text>
     </xsl:if>
    </SPAN>
    <xsl:apply-templates select="@*"/>
    <SPAN class="m">
     <xsl:text>></xsl:text>
    </SPAN>
    <SPAN class="tx">
     <xsl:value-of select="."/>
    </SPAN>
    <SPAN class="m">&lt;/</SPAN>
    <SPAN>
     <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
     <xsl:value-of select="name(.)"/>
    </SPAN>
    <SPAN class="m">
     <xsl:text>></xsl:text>
    </SPAN>
   </DIV>
  </DIV>
 </xsl:template>
 <xsl:template match="*[*]" priority="20">
  <DIV class="e">
   <DIV STYLE="margin-left:1em;text-indent:-2em" class="c">
    <A class="b" href="#" onclick="return false" onfocus="h()">-</A>
    <SPAN class="m">&lt;</SPAN>
    <SPAN>
     <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
     <xsl:value-of select="name(.)"/>
     <xsl:if test="@*">
      <xsl:text> </xsl:text>
     </xsl:if>
    </SPAN>
    <xsl:apply-templates select="@*"/>
    <SPAN class="m">
     <xsl:text>></xsl:text>
    </SPAN>
   </DIV>
   <DIV>
    <xsl:apply-templates/>
    <DIV>
     <SPAN class="b">
      <xsl:call-template name="entity-ref">
       <xsl:with-param name="name">nbsp</xsl:with-param>
      </xsl:call-template>
     </SPAN>
     <SPAN class="m">
      <xsl:text>&lt;/</xsl:text>
     </SPAN>
     <SPAN>
      <xsl:attribute name="class"><xsl:if test="xsl:*"><xsl:text>x</xsl:text></xsl:if><xsl:text>t</xsl:text></xsl:attribute>
      <xsl:value-of select="name(.)"/>
     </SPAN>
     <SPAN class="m">
      <xsl:text>></xsl:text>
     </SPAN>
    </DIV>
   </DIV>
  </DIV>
 </xsl:template>
 <xsl:template name="entity-ref">
  <xsl:param name="name"/>
  <xsl:text disable-output-escaping="yes">&amp;</xsl:text>
  <xsl:value-of select="$name"/>
  <xsl:text>;</xsl:text>
 </xsl:template>
</xsl:stylesheet>

I want to reiterate that the xslt file content is not my work. I got it from the internet. I am posting it here for the convenience of some poor soul like me.

Regards,

Sid

Siddhartha
       
Sponsored by
Become a Sponsor
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
SQL and .NET performance profiling in one place
Investigate SQL and .NET code side-by-side with ANTS Performance Profiler 6, so you can see which is causing the problem without switching tools.
60 FREE UI Controls from DevExpress
Register for your FREE copy on over 60 free presentation controls from DevExpress - Absolutely Free-of-Charge without any royalties or distribution costs. Visit Devexpress.com/60 today. Free controls include advanced lists box, dropdown calendar, rich text edit, spin edit, tab control and so much more!

DevExpress engineers feature rich presentation controls and reporting tools for WinForms, ASP.NET, WPF, and Silverlight. Our technologies help you build your best, see complex software with greater clarity and deliver compelling business solutions for Windows and the web in the shortest possible time.
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Visualize your workspace with new multiple monitor support, powerful Web development, new SharePoint support with tons of templates and Web parts, and more accurate targeting of any version of the .NET Framework. Get set to unleash your creativity.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Unlimited Access to 10,000 Tech Books & Videos, 15 Days, $0
Unlimited Access to 10,000 Tech Books & Videos, 15 Days, $0
Top Microsoft Certification Books & Videos, 15 Days, $0
Top Microsoft Certification Books & Videos, 15 Days, $0

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Advertise with us
Current Version: 3.2009.8.27
 © 1999 - 2010  Mindcracker LLC. All Rights Reserved