PDA

View Full Version : javascript and xml help



chuco61
10-10-2008, 06:58 PM
I have two files. a javascript file that calls in an xml weather file. For some reason i cannot have it call up the specific values i want. I believe its calling up the first child. Other than that i dont know how to call up specifically the three values i want at the same time.

Can someone help me out.

Javascript code:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Document</title>
</head>

<body>
<script language="JavaScript1.2">

/*
DOM XML ticker- Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and Terms Of Use, visit http://www.dynamicdrive.com
Credit MUST stay intact
*/

//Container for ticker. Modify its STYLE attribute to customize style:
var tickercontainer='<div id="units" style="background-color:#FFFFE1;width:150px;height:120px;font:normal 13px Verdana;"></div>'

//Specify path to xml file
var xmlsource="ticker.xml"

////No need to edit beyond here////////////
//load xml file
if (window.ActiveXObject)
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
else if (document.implementation && document.implementation.createDocument)
var xmlDoc= document.implementation.createDocument("","doc",null);
if (typeof xmlDoc!="undefined"){
document.write(tickercontainer)
xmlDoc.load(xmlsource)
}

//Regular expression used to match any non-whitespace character
var notWhitespace = /\S/

function init_ticker(){
//Cache "messages" element of xml file
tickerobj=xmlDoc.getElementsByTagName("xmlticker")[0]

//REMOVE white spaces in XML file. Intended mainly for NS6/Mozilla
for (i=0;i<tickerobj.childNodes.length;i++){
if ((tickerobj.childNodes[i].nodeType == 3)&&(!notWhitespace.test(tickerobj.childNodes[i].nodeValue))) {
tickerobj.removeChild(tickerobj.childNodes[i])
i--
}
}
document.getElementById("units").innerHTML=tickerobj.childNodes[1].firstChild.nodeValue
msglength=tickerobj.childNodes.length
currentmsg=0
themessage=''
setInterval("rotatemsg()",tickerobj.childNodes[0].firstChild.nodeValue)
}

function rotatemsg(){
var msgsobj=tickerobj.childNodes[currentmsg]
if (msgsobj.getAttribute("url")!=null){
themessage='<a href="'+msgsobj.getAttribute("url")+'"'
if (msgsobj.getAttribute("target")!=null)
themessage+=' target="'+msgsobj.getAttribute("target")+'"'
themessage+='>'
}
themessage+=msgsobj.firstChild.nodeValue
if (msgsobj.getAttribute("url")!=null)
themessage+='</a>'

//Rotate msg and display it in DIV:
document.getElementById("units").innerHTML=themessage
currentmsg=(currentmsg<msglength-3)? currentmsg+1 : 1
themessage=''
}


function fetchxml(){
if (xmlDoc.readyState==4)
init_ticker()
else
setTimeout("fetchxml()",10)
}

if (window.ActiveXObject)
fetchxml()
else if (typeof xmlDoc!="undefined")
xmlDoc.onload=init_ticker

</script>
</body>
</html>


XML code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmlticker>
<units>
<temp>C</temp>
<dist>km</dist>
<speed>km/h</speed>
<pres>KPA</pres>
<prec>mm</prec>
</units>

<local>

<city>Gilroy</city>
<state>CA</state>
<lat>37.02</lat>
<lon>-121.57</lon>
<time>15:53</time>
<timeZone>-8</timeZone>
<obsDaylight>1</obsDaylight>
</local>
<currentconditions>
<temperature>36</temperature>
<realfeel>38</realfeel>
<weathertext>Sunny</weathertext>
<weathericon>01</weathericon>
<windspeed>6</windspeed>
<winddirection>SSW</winddirection>
</currentconditions>
<forecast>
<day number="1">
<obsdate>9/23/2008</obsdate>
<daycode>Tuesday</daycode>
<daytime>
<txtshort>Plenty of sunshine</txtshort>
<txtlong>Plenty of sunshine</txtlong>
<weathericon>01</weathericon>
<hightemperature>35</hightemperature>
<lowtemperature>9</lowtemperature>
<windspeed>6</windspeed>
<winddirection>NNW</winddirection>
<windgust>19</windgust>
</daytime>
<nighttime>
<txtshort>Clear</txtshort>
<txtlong>Clear</txtlong>
<weathericon>33</weathericon>
<hightemperature>35</hightemperature>
<lowtemperature>9</lowtemperature>
<windspeed>6</windspeed>
<winddirection>SSE</winddirection>
<windgust>19</windgust>
</nighttime>
</day>
</forecast>

<copyright>Copyright 2008 AccuWeather.com</copyright>

<use>
This document is intended only for use by authorized licensees of AccuWeather.com. Unauthorized use is prohibited. All Rights Reserved.
</use>
<product>main street media</product>
<redistribution>Redistribution Prohibited.</redistribution>
</xmlticker>


Out of all this XML i only need: Temperatue, weather text and weather icon to appear at the same time. no need for it to cylce through either.

PLeas :confused::confused::confused::mad:e help!

chuco61
10-12-2008, 02:11 AM
anyone?

chuco61
10-14-2008, 06:06 PM
anyone please?