Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > HTML / XHTML
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 03-30-2006, 06:59 PM
  #1
amerikaner1999
Novice (Level 1)
 
Join Date: Mar 2006
Posts: 7
iTrader: (0)
amerikaner1999 is an unknown quantity at this point
adding XML weather feed to an HTML page

I want to add an XML weather feed to an HTML page.

The amount of tutorials for the beginners seem very sparse based on my google searches.

This is the code I used:

<div align="center"><xml id="note" src="http://informer.gismeteo.ru/xml/27581_1.xml"></xml></div>

<tr>
<td><span datafld="TEMPERATURE"></span></td>
<td><span datafld="TOWN"></span></td>
</tr>
</table>
</div>

Nothing comes up in the page except the tables. What am I doing wrong?
amerikaner1999 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-30-2006, 09:05 PM
  #2
bobfunland
Paladin (Level 15)
 
bobfunland's Avatar
 
Join Date: Jun 2005
Location: Galactic Sector ZZ9 Plural Z Alpha
Posts: 355
iTrader: (0)
bobfunland is an unknown quantity at this point
If I'm not mistaken, html has no xml tag and usage of such will be ignored by most browsers. To do what you want would likely require at least one of the following: iframe, scripts, server side programming, etc. Somebody more knowledgeable than me can fill you in on the rest.
__________________

Don't like my signature? Click on it to make a new one!
bobfunland is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-30-2006, 11:27 PM
  #3
amerikaner1999
Novice (Level 1)
 
Join Date: Mar 2006
Posts: 7
iTrader: (0)
amerikaner1999 is an unknown quantity at this point
oh dear , sounds a lot more complicated than i had anticipated.


Should I have started out with an .xhtml page? I'm using dreamweaver
amerikaner1999 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 03-31-2006, 04:07 AM
  #4
bendman
Semantic Fanatic
 
bendman's Avatar
 
Join Date: Jun 2004
Location: Washington, DC
Posts: 1,301
iTrader: (0)
bendman is on a distinguished road
ok, I made a script that should do what you want (I added more fields than you mentioned so you can see how it works). You need to run it on a server that supports php (most do, you should be ok), and javascript needs to be turned on (usually is). The body section of your HTML file would look something like this, don't forget the "<body onload=...>"
HTML Code:
<body onload='getData("xmlfeed.php", "http://informer.gismeteo.ru/xml/27581_1.xml")'>
<script language='javascript'>
function getData(dataSrc, urlSrc) {
	if (window.ActiveXObject){
		XMLHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		XMLHttpObj = new XMLHttpRequest();
	}
	if (XMLHttpObj) {
		XMLHttpObj.onreadystatechange = function() {
			if (XMLHttpObj.readyState == 4) {
				try {
					if (XMLHttpObj.status == 200) {
						var XMLData = (new DOMParser()).parseFromString(XMLHttpObj.responseText, "text/xml");
						removeWhiteSpace(XMLData);
						var weatherTable = document.getElementById('weathertable');
						var reportNode = XMLData.firstChild.firstChild;
						while (reportNode) {
							townNode = reportNode.firstChild;
							while (townNode) {
								townIndex = '<td>' + townNode.attributes[0].nodeValue + '<\/td>';
								forecastNode = townNode.firstChild;
								while (forecastNode) {
									forecastTempMin = '<td>' + forecastNode.childNodes[2].attributes[1].nodeValue + '<\/td>';
									forecastTempMax = '<td>' + forecastNode.childNodes[2].attributes[0].nodeValue + '<\/td>';
									forecastYear = '<td>' + forecastNode.attributes[2].nodeValue + '<\/td>';
									forecastMonth = '<td>' + forecastNode.attributes[1].nodeValue + '<\/td>';
									forecastDay = '<td>' + forecastNode.attributes[0].nodeValue + '<\/td>';
									forecastHour = '<td>' + forecastNode.attributes[3].nodeValue + '<\/td>';
									weatherTable.innerHTML += '<tr>' + townIndex + forecastTempMin + forecastTempMax + forecastHour + forecastDay + forecastMonth + forecastYear + '<\/tr>\n';
									forecastNode = forecastNode.nextSibling;
								}
								townNode = townNode.nextSibling;
							}
							reportNode = reportNode.nextSibling;
						}
					} else {
						var errorMsg = '\'' + XMLHttpObj.status + ' Error\' for file ' + dataSrc;
						alert(errorMsg);
					}
				} catch(e) {
				}
			}
		};
		dataSrc = dataSrc + '\?urlsrc\=' + urlSrc;
		XMLHttpObj.open("GET", dataSrc, true);
		XMLHttpObj.send(null);
	}
}

function removeWhiteSpace(xml) {
	var loopIndex;
	for (loopIndex = 0; loopIndex < xml.childNodes.length; loopIndex++) {
		var currentNode = xml.childNodes[loopIndex];
		if (currentNode.nodeType == 1) {
			removeWhiteSpace(currentNode);
		}
		if (((/^\s+$/.test(currentNode.nodeValue))) && (currentNode.nodeType == 3)) {
			xml.removeChild(xml.childNodes[loopIndex--]);
		}
	}
}
</script>

<table id='weathertable'>
	<tr>
		<td>Town Index</td>
		<td>Minimum</td>
		<td>Maximum</td>
		<td>Hour</td>
		<td>Day</td>
		<td>Month</td>
		<td>Year</td>
	</tr>
</table>

</body>
and then you need to upload this file into the same directory as your HTML file and name it "xmlfeed.php" Keep in mind that because this file is serverside you will only be able to view the page online, not on your hard-drive.
PHP Code:
<?php
$xmlfilestring 
implode(''file($_GET['urlsrc']));
echo 
$xmlfilestring;
?>
To view an example of what this code outputs, go to http://bendman.unssfree.com/xmlfeed.html.

A good tutorial about how to view XML files in pages is at http://www.w3schools.com/dom/default.asp, and for more information on exactly what I did to get the file into the page, you can look at this post (the only difference is that it's in PHP here, but ASP there, the principles are the same).

Hope this helps!

bendman
__________________
[twitter] [facebook]
bendman is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Reply
KEEP TABS
SPONSORS
 
Boxedart

 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 02:06 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.