This is a discussion on "How to refresh XML data" within the Other Programming Languages section. This forum, and the thread "How to refresh XML data are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
How to refresh XML data
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
How to refresh XML data
Hi All,
I'm a newbie at Javascript, and have managed to get a project for my employer working... almost. All I'm doing is using Internet Explorer 6.xx to read in an XML sheet from an internal server and display it in a table. Why did I use javascript? I need to change one table cell to red or green depending on if the data in that cell is "OK" or "FAULT". This way the operator can have a visual cue that there is a problem, even if he is sitting across the room. There are up to 60 cells that can change color. Ok enough background. It all works fine except that the Meta tag "refresh" only refreshes the browsers cache. I need to reload the XML file to show any changes, and they happen frequently at any time.Suprisingly. hitting the BACK button does reload the XML file. ???? I can send the work in progress to anyone interested. I've Googled suggestions about using JAvascript to refresh and tried the examples, but the Browser just ignores it. Crashcup |
|
|
|
|||
|
Here is the HTML file I'm working on.
<code> <html> <head> <META http-equiv="expires" content="0"> </HEAD> <BODY> <script language="JavaScript" for="window" event="onload"> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("linegard.xml") nodes = xmlDoc.documentElement.childNodes PV1 = nodes(0).firstChild.text PV2 = nodes(1).firstChild.text PV3 = nodes(2).firstChild.text PV4 = nodes(3).firstChild.text PV5 = nodes(4).firstChild.text PV6 = nodes(5).firstChild.text PV7 = nodes(6).firstChild.text PV8 = nodes(7).firstChild.text PV9 = nodes(8).firstChild.text PV10 = nodes(9).firstChild.text PV11 = nodes(10).firstChild.text PV12 = nodes(11).firstChild.text PV13 = nodes(12).firstChild.text PV14 = nodes(13).firstChild.text PV15 = nodes(14).firstChild.text PV16 = nodes(15).firstChild.text Name1 = nodes(16).firstChild.text Name2 = nodes(17).firstChild.text Name3 = nodes(18).firstChild.text Name4 = nodes(19).firstChild.text Name5 = nodes(20).firstChild.text Name6 = nodes(21).firstChild.text Name7 = nodes(22).firstChild.text Name8 = nodes(23).firstChild.text Name9 = nodes(24).firstChild.text Name10 = nodes(25).firstChild.text Name11 = nodes(26).firstChild.text Name12 = nodes(27).firstChild.text Name13 = nodes(28).firstChild.text Name14 = nodes(29).firstChild.text Name15 = nodes(30).firstChild.text Name16 = nodes(31).firstChild.text SP1 = nodes(32).firstChild.text SP2 = nodes(33).firstChild.text SP3 = nodes(34).firstChild.text SP4 = nodes(35).firstChild.text SP5 = nodes(36).firstChild.text SP6 = nodes(37).firstChild.text SP7 = nodes(38).firstChild.text SP8 = nodes(39).firstChild.text SP9 = nodes(40).firstChild.text SP10 = nodes(41).firstChild.text SP11 = nodes(42).firstChild.text SP12 = nodes(43).firstChild.text SP13 = nodes(44).firstChild.text SP14 = nodes(45).firstChild.text SP15 = nodes(46).firstChild.text SP16 = nodes(47).firstChild.text AN1 = nodes(48).firstChild.text AN2 = nodes(49).firstChild.text AN3 = nodes(50).firstChild.text AN4 = nodes(51).firstChild.text AN5 = nodes(52).firstChild.text AN6 = nodes(53).firstChild.text AN7 = nodes(54).firstChild.text AN8 = nodes(55).firstChild.text AN9 = nodes(56).firstChild.text AN10 = nodes(57).firstChild.text AN11 = nodes(58).firstChild.text AN12 = nodes(59).firstChild.text AN13= nodes(60).firstChild.text AN14= nodes(61).firstChild.text AN15= nodes(62).firstChild.text AN16= nodes(63).firstChild.text Status1= nodes(64).firstChild.text Status2= nodes(65).firstChild.text Status3= nodes(66).firstChild.text Status4= nodes(67).firstChild.text Status5= nodes(68).firstChild.text Status6= nodes(69).firstChild.text Status7= nodes(70).firstChild.text Status8= nodes(71).firstChild.text Status9= nodes(72).firstChild.text Status10= nodes(73).firstChild.text Status11= nodes(74).firstChild.text Status12= nodes(75).firstChild.text Status13= nodes(76).firstChild.text Status14= nodes(77).firstChild.text Status15= nodes(78).firstChild.text Status16= nodes(79).firstChild.text Units1= nodes(80).firstChild.text Units2= nodes(81).firstChild.text Units3= nodes(82).firstChild.text Units4= nodes(83).firstChild.text Units5= nodes(84).firstChild.text Units6= nodes(85).firstChild.text Units7= nodes(86).firstChild.text Units8= nodes(87).firstChild.text Units9= nodes(88).firstChild.text Units10= nodes(89).firstChild.text Units11= nodes(90).firstChild.text Units12= nodes(91).firstChild.text Units13= nodes(92).firstChild.text Units14= nodes(93).firstChild.text Units15= nodes(94).firstChild.text Units16= nodes(95).firstChild.text T1 = nodes(96).firstChild.text row2col1var = 'OK' row2col2var = 'FAULT' S1Color = '"GREEN"' S2Color = 'BGCOLOR="RED"' document.write('<CAPTION ALIGN="LEFT"> ' + T1 + '</CAPTION>'); document.write('<center><TABLE BORDER="4" CELLPADDING="4" CELLSPACING="1" BGCOLOR="#EEEE70">'); document.write('<TR>'); document.write('<TD ROWSPAN="1" WIDTH="50" HEIGHT="40" ALIGN="CENTER">Input</TD>'); document.write('<TD ROWSPAN="1" WIDTH="400" HEIGHT="30" ALIGN="CENTER"> Sensor Location </TD>'); document.write('<TD ROWSPAN="1" WIDTH="50" HEIGHT="30" ALIGN="CENTER">Units</TD>'); document.write('<TD ROWSPAN="1" WIDTH="50" HEIGHT="30" ALIGN="CENTER">PV</TD>'); document.write('<TD ROWSPAN="1" WIDTH="50" HEIGHT="30" ALIGN="CENTER">SP</TD>'); document.write('<TD ROWSPAN="1" WIDTH="90" HEIGHT="30" ALIGN="CENTER">STATUS</TD>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN1 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name1 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units1 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV1 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP1 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status1 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN2 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name2 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units2 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV2 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP2 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status2 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN3 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name3 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units3 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV3 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP3 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status3 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN4 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name4 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units4 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV4 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP4 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status4 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN5 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name5 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units5 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV5 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP5 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status5 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN6 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name6 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units6 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV6 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP6 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status6 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN7 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name7 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units7 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV7 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP7 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status7 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN8 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name8 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units8 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV8 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP8 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status8 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN9 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name9 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units9 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV9 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP9 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status9 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN10 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name10 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units10 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV10 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP10 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status10 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN11 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name11 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units11 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV11 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP11 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status11 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN12 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name12 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units12 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV12 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP12 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status12 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN13 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name13 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units13 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV13 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP13 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status13 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN14 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name14 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units14 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV14 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP14 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status14 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN15 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name15 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units15 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV15 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP15 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status15 + ' </td>'); document.write('</TR>'); document.write('<TR>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + AN16 + ' </td>'); document.write('<TD WIDTH="400" ALIGN="LEFT" ' + Name16 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + Units16 + ' </TD>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + PV16 + ' </td>'); document.write('<TD WIDTH="50" ALIGN="CENTER" ' + SP16 + ' </td>'); //document.write('<TD WIDTH="50"' + 'BGCOLOR=' + S1Color +' OK </td>'); document.write('<TD WIDTH="50"' + S2Color +' ' + Status16 + ' </td>'); document.write('</TR>'); document.write('</table></center>'); </script> </BODY> </HTML> </code> Here is the XML file.......... <Note> <PV1>111</PV1> <PV2>200</PV2> <PV3>5.6</PV3> <PV4>5.56</PV4> <PV5>7.8</PV5> <PV6>5.5</PV6> <PV7>0</PV7> <PV8>0</PV8> <PV9>4</PV9> <PV10>160</PV10> <PV11>70.3</PV11> <PV12>80.3</PV12> <PV13>0</PV13> <PV14>0</PV14> <PV15>15.1</PV15> <PV16>15.8</PV16> <Name1>Room Temperature</Name1> <Name2>Room Temperature</Name2> <Name3>Room Temperature</Name3> <Name4>Room Temperature</Name4> <Name5>Stage-1</Name5> <Name6>6</Name6> <Name7>Stage-2 Fluoride</Name7> <Name8>analog 8</Name8> <Name9>Stage-3 Temperature</Name9> <Name10>10</Name10> <Name11>Stage-4</Name11> <Name12>12</Name12> <Name13>13</Name13> <Name14>Stage-5 Temperature</Name14> <Name15>Stage-6 Conductivity</Name15> <Name16>16</Name16> <SP1>100</SP1> <SP2>222</SP2> <SP3>6</SP3> <SP4>4</SP4> <SP5>6</SP5> <SP6>5</SP6> <SP7>4</SP7> <SP8>9</SP8> <SP9>4</SP9> <SP10>60</SP10> <SP11>70</SP11> <SP12>80</SP12> <SP13>90</SP13> <SP14>100</SP14> <SP15>15.1</SP15> <SP16>16.1</SP16> <AN1>1</AN1> <AN2>2</AN2> <AN3>3</AN3> <AN4>4</AN4> <AN5>5</AN5> <AN6>6</AN6> <AN7>7</AN7> <AN8>8</AN8> <AN9>9</AN9> <AN10>10</AN10> <AN11>11</AN11> <AN12>12</AN12> <AN13>13</AN13> <AN14>14</AN14> <AN15>15</AN15> <AN16>16</AN16> <Status1>Ok</Status1> <Status2>Ok</Status2> <Status3>Alarm</Status3> <Status4>Ok</Status4> <Status5>Alarm</Status5> <Status6>Alarm</Status6> <Status7>Alarm</Status7> <Status8>Alarm</Status8> <Status9>Ok</Status9> <Status10>Ok</Status10> <Status11>Alarm</Status11> <Status12>Ok</Status12> <Status13>Ok</Status13> <Status14>Alarm</Status14> <Status15>Alarm</Status15> <Status16>Ok</Status16> <Units1>F</Units1> <Units2>F</Units2> <Units3>F</Units3> <Units4>F</Units4> <Units5>pH</Units5> <Units6>F</Units6> <Units7>mL</Units7> <Units8>F</Units8> <Units9>F</Units9> <Units10>F</Units10> <Units11>F</Units11> <Units12>F</Units12> <Units13>F</Units13> <Units14>F</Units14> <Units15>mS</Units15> <Units16>F</Units16> <Time>5:17:43 PM</Time> </Note> |
|
|||
|
You actually don't need to use Javascript at all to conditionally change the appearance of your data based on its values. All you need to do is create a XSLT to transform your XML file and it'll do all that for you in a much simpler way.
About XSLT: http://www.w3schools.com/xsl/default.asp Using IF in XSLT: http://www.w3schools.com/xsl/xsl_if.asp Applying an XSLT using javascript: http://www.w3schools.com/xsl/xsl_client.asp This'll save you a lot of work in the long run. If you do something like that, then you could write a javascript function to display, then clear and redisplay the data using a time (setInterval). See document.clear() and http://msdn.microsoft.com/library/de...etinterval.asp for more info. |
![]() |
| Tags |
| refresh, xml, data |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to stop the browser refresh on clicking the webbrowser's refresh button ? | camarun20 | JavaScript Forum | 3 | Mar 18th, 2008 23:04 |
| When Refresh go 1 again | gncreditcards | Web Page Design | 2 | Jan 30th, 2008 18:24 |
| Code for button to refresh page after inserting data in sql db | wacara | JavaScript Forum | 0 | Apr 27th, 2007 02:45 |
| How does a page refresh? | flox74 | Web Page Design | 8 | May 8th, 2006 19:41 |
| prevent refresh in asp | simonneaves | Classic ASP | 2 | Oct 10th, 2005 09:04 |