通过按钮刷新xml文件

时间:2011-09-15 05:46:56

标签: asp.net xml

我正在使用带有标签的asp网络应用程序。当我单击该选项卡时,将读取xml文件。该xml文件中包含数据。该xml文件具有指向xslt文件的href,其中我编写了用于创建表的代码,用于在浏览器中以可呈现的方式在xml文件中显示xml数据。

用户可以更改xml文件中的数据,也可以在运行时删除一些数据。我在xslt文件中包含了一个刷新按钮。在运行时,如果用户对xml文件进行了更改,我希望单击刷新按钮以反映网页中表格中的更改。我只想刷新xml文件,相应的更改将反映在网页中。

我该怎么做?我已在上面上传了我的代码:

ASPX文件

<%@ Page Title="Home Page" Language="C#"  AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="sampleapp._Default" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<html>
<head id="Head1" runat="server">
<meta http-equiv="Cache-Control" content="no-cache"/>
        <meta http-equiv="Pragma" content="no-cache"/>
        <meta http-equiv="Expires" content="0"/>

        <title>VPGate Configuration</title>
        <link rel="stylesheet" type="text/css" href="office2007.css"/>
        <link rel="stylesheet" type="text/css" href="style002.css"/>
         <script language="javascript" type="text/javascript">
             function window.onload() {
                 try {
                     if (self != top)
                         self.parent.location = document.location;

                 }
                 catch (Exception) { }
             }
        </script>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>
 <script type="text/javascript">
     function OnClientTabSelected(sender, eventArgs) {
         var tab = eventArgs.get_tab();
         if (tab.get_tabs().get_count() > 0) {
             tab.get_tabs().getTab(0).select();
             //tab.get_tabs().getTab(0).click();
         }
         if (tab.get_text() == "Help") {
             document.getElementById("helpframe").style.display = "inline";
             document.getElementById("framebody").style.display = "none";
             document.getElementById("framebody").src = "";
             if (document.getElementById("helpframe").src == "")
                 document.getElementById("helpframe").src = "/help/ApplicationHelp.htm";
         }
         else {
             document.getElementById("helpframe").style.display = "none";
             document.getElementById("framebody").style.display = "inline";
         }
     }
     function OnClientTabSelecting(sender, eventArgs) {
         if (!formchk2()) {
             eventArgs.set_cancel(true);
             return false;
         }
     }
    </script>
 <telerik:RadTabStrip ID="tab1" runat="server" ShowBaseLine="True" 
            EnableEmbeddedSkins="False" ClickSelectedTab="True" 
            UnSelectChildren="True" SelectedIndex="3" 
            OnClientTabSelected="OnClientTabSelected" Skin="Office2007" style="margin-left: 29px;border-left-style:none;"
    OnClientTabSelecting="OnClientTabSelecting">
    <Tabs>
     <telerik:RadTab Text="General" NavigateUrl="ShowXML.aspx?file=MMDiagnostics.xml" Target="framebody" Selected="true"></telerik:RadTab>
    </Tabs>
      </telerik:RadTabStrip>
     <iframe id="framebody" name="framebody"   runat="server"
            style="border-left: thin solid #4173be; border-right: thin solid #4173be; border-bottom: thin solid #4173be; height:112%; width:100%; border-top-width:0px; border-top-color:White; 
             background-color:white; float:left;height:92.5%; width:97.4%; margin-left:9.5px;" 
            frameborder="0" scrolling="no">
    </iframe>
      </form>
      </body>
</html>

XML文件

<?xml-stylesheet type="text/xsl" href="MMDiagnostics.xslt"?>

<MediaMixer>

  <Conference>
    <Name>Test001</Name>
    <ConfId>1000</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48000</CompositePort>
    <CompositeSsrc>243324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>80542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.40</ParticipantAddress>
      <ParticipantListeningPort>22000</ParticipantListeningPort>
      <MMListeningPort>45000</MMListeningPort>
      <SSRCFromParticipant>216541</SSRCFromParticipant>
      <SSRCFromMM>56481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>80542151</ID1>
      <ID2>harish</ID2>
      <ParticipantAddress>192.168.177.40</ParticipantAddress>
      <ParticipantListeningPort>22000</ParticipantListeningPort>
      <MMListeningPort>45000</MMListeningPort>
      <SSRCFromParticipant>216541</SSRCFromParticipant>
      <SSRCFromMM>56481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>7825482</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.22</ParticipantAddress>
      <ParticipantListeningPort>22002</ParticipantListeningPort>
      <MMListeningPort>45002</MMListeningPort>
      <SSRCFromParticipant>3256</SSRCFromParticipant>
      <SSRCFromMM>14822456</SSRCFromMM>
    </Participant>

  </Conference>

  <Conference>
    <Name>Test002</Name>
    <ConfId>1002</ConfId>
    <CompositeAddress>238.57.0.1</CompositeAddress>
    <CompositePort>48005</CompositePort>
    <CompositeSsrc>353324353</CompositeSsrc>
    <NoOfParticipants>2</NoOfParticipants>

    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>
    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>
    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>
    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>
    <Participant>
      <ID1>70542151</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.45</ParticipantAddress>
      <ParticipantListeningPort>22004</ParticipantListeningPort>
      <MMListeningPort>45004</MMListeningPort>
      <SSRCFromParticipant>316541</SSRCFromParticipant>
      <SSRCFromMM>26481</SSRCFromMM>
    </Participant>

    <Participant>
      <ID1>5625482</ID1>
      <ID2>0</ID2>
      <ParticipantAddress>192.168.177.20</ParticipantAddress>
      <ParticipantListeningPort>22006</ParticipantListeningPort>
      <MMListeningPort>45006</MMListeningPort>
      <SSRCFromParticipant>8256</SSRCFromParticipant>
      <SSRCFromMM>41822456</SSRCFromMM>
    </Participant>

  </Conference>

</MediaMixer>

XSLT文件

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">

    <html>
      <head>
        <title>VPGate Media Mixer</title>

        <meta http-equiv="expires" content="0"/>
        <meta http-equiv="pragma" content="no-cache"/>
        <meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
        <meta http-equiv="refresh" content="15"></meta>
        <script src="/Common/common.js\" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="style001.css" />
        <link rel="stylesheet" type="text/css" href="Grid.Default.css" />


      </head>

      <body class="WorkArea">       
        <div class="divSummaryHeader" id="SummaryHeader">
          <h1>Media Mixer - VPGate</h1>

          <xsl:for-each select="MMDiagnostics/Conference">
            <h1>
              Media Mixer - <xsl:value-of select="name"/>
            </h1>
          </xsl:for-each>
        </div>

        &#160;



        <div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:630px;overflow:auto">

          <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
            <tr>
              <input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>

              </tr>
              <tr>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference</td>
              </tr>

              <tr>
                <td>
                  <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
                    <tr>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Name</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Id</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
                    </tr>

                    <xsl:for-each select="MediaMixer/Conference">
                      <!--<xsl:sort select="Name"/>-->
                      <xsl:if test="(position() mod 2 = 0)">

                        <tr class="rgAltRow SummaryTableDataRow">
                          <td valign = "top">
                            <xsl:value-of select="Name"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ConfId"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="CompositeAddress"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="CompositePort"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="CompositeSsrc"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="NoOfParticipants"/>
                          </td>
                        </tr>
                      </xsl:if>

                      <xsl:if test="(position() mod 2 = 1)">
                        <td bgcolor="#aaaaff">
                          <tr class="rgAltRow SummaryTableDataRow">
                            <td valign = "top">
                              <xsl:value-of select="Name"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ConfId"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="CompositeAddress"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="CompositePort"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="CompositeSsrc"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="NoOfParticipants"/>
                            </td>
                          </tr>
                        </td>
                      </xsl:if>

                    </xsl:for-each>

                  </table>
                </td>
              </tr>
            </table>

            &#160;

            <table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1" >
              <tr>
                <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Participant</td>
              </tr>

              <tr>
                <td>

                  <table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
                    <tr>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 1</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 2</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
                      <td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
                    </tr>

                    <xsl:for-each select="MediaMixer/Conference/Participant">

                      <xsl:if test="(position() mod 2 = 0)">

                        <tr class="rgAltRow SummaryTableDataRow">
                          <td valign = "top">
                            <xsl:value-of select="ID1"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ID2"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ParticipantAddress"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="ParticipantListeningPort"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="MMListeningPort"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="SSRCFromParticipant"/>
                          </td>
                          <td valign = "top">
                            <xsl:value-of select="SSRCFromMM"/>
                          </td>
                        </tr>
                      </xsl:if>

                      <xsl:if test="(position() mod 2 = 1)">
                        <td bgcolor="#aaaaff">
                          <tr class="rgAltRow SummaryTableDataRow">
                            <td valign = "top">
                              <xsl:value-of select="ID1"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ID2"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ParticipantAddress"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="ParticipantListeningPort"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="MMListeningPort"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="SSRCFromParticipant"/>
                            </td>
                            <td valign = "top">
                              <xsl:value-of select="SSRCFromMM"/>
                            </td>

                          </tr>
                        </td>
                      </xsl:if>
                    </xsl:for-each>

                  </table>
                </td>
              </tr>
            </table>


            &#160;


            <div style="display:none">
              <iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
            </div>


          </div>

          </body> 
    </html>
    </xsl:template>
</xsl:stylesheet>

2 个答案:

答案 0 :(得分:0)

您可以使用setTimeout函数在客户端设置计时器。 每次你可以阅读xml并检查修改日期 的文件。或者例如在XML changedDate中设置属性并检查它 每次。如果它从前一个更改,您可以刷新xml。

答案 1 :(得分:0)

正如我之前所说,您可以检查xml的修改数据或在XML中设置属性“ModifiedDate”。 当有人更新XML时,他必须更改更新attribure。