How to get data from xml into table in C#

215 Views Asked by At

I have a check box when I check it and click on continue, I want to read all the data from xml file and put that into the table with one column showing hyperlink which will help user to add or edit the data to save or update.

Radio Button code:

 <input type="radio" value="Yes" id="RBServer" name="radio4">Server</td>

When I click on continue, then I am trying to read xslt file. Code as follows:

Javascript as follows:

var testRadio = document.getElementById('RBServer');
 if (testRadio.checked==true)
    {
        var style = new ActiveXObject("Microsoft.xmldom");
        style.async = false;
        style.load("Server.xslt");
        document.all.targetHTML.innerHTML = source.transformNode(style);
    }

I have create Server.XSLT file Like this

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
      <html>
        <body style="font-family:Helvetica Neue">
          <Div id="ListingScreen1">
            <table border="1" width="1024px" >
              <tr>
                <th>Server</th>
                <th>ID</th>           
              </tr>
              <xsl:choose>
                <xsl:when test="CATALOG/orderByTitle">
                  <xsl:apply-templates select="CATALOG/CD">
                    <!--<xsl:sort select="TITLE" />-->
                  </xsl:apply-templates>
                </xsl:when>
                <xsl:when test="CATALOG/orderByTitleDesc">
                  <xsl:apply-templates select="CATALOG/CD">
                    <!--<xsl:sort select="TITLE" order="ascending" />-->
                  </xsl:apply-templates>
                </xsl:when>
                <xsl:when test="CATALOG/orderByArtist">
                  <xsl:apply-templates select="CATALOG/CD">
                    <!--<xsl:sort select="ARTIST" />-->
                  </xsl:apply-templates>
                </xsl:when>
              </xsl:choose>
            </table>

          </Div>
        </body>
            </html>
        <!--<xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>-->


    </xsl:template>

  <xsl:template match="CD">
    <tr>
      <td>
        <!--<xsl:value-of select="ID"/>-->
      </td>
      <td onclick="javascript:FillEditScreen(this.innerText);">
        <a href="javascript:void(0);">
          <p style="display:none;">
            <xsl:value-of select="Server"/>
          </p>
          <xsl:value-of select="ID"/>
        </a>
      </td>
    </tr>
  </xsl:template>
</xsl:stylesheet>

And my xml file is like this :Server.xml

<?xml version="1.0" encoding="utf-8"?>
<CATALOG>
  <orderByTitleDesc />
  <CD>
    <Server>KL12ACUC.CS.AD.KLMCORP.NET</Server>
    <ID>KL12ACUC.CS.AD.KLMCORP.NET</ID>
  </CD>
  <CD>
    <Server>basant112</Server>
    <ID>basant</ID>
  </CD>
</CATALOG>
0

There are 0 best solutions below