<%@LANGUAGE=Python%>
<%
# Licence GPL
# se
http://support.microsoft.com/kb/276494 der er beskrevet hvordan du
# opsætter din asp server til at bruge python
import sys
import pdb
from xml.dom.ext.reader.Sax2 import FromXmlStream
from xml.dom.ext import PrettyPrint
# get DOM object
xmlFile = open("fra.xml")
doc = FromXmlStream( xmlFile )
Values = {}
# pdb.set_trace()
for elements in doc.getElementsByTagName("dataelement"):
elements.normalize()
for Typer in elements.getElementsByTagName("type"):
type = Typer.firstChild.data
for Byer in elements.getElementsByTagName("location"):
town = Byer.firstChild.data
for Value in elements.getElementsByTagName("value"):
value = Value.firstChild.data
try:
Values[ town ][ type ] = value
except:
Values[ town ] = { type:value }
data = Values.items()
Response.Write( """<?xml version="1.0" encoding="UTF-8"?>
<Weather>
<Towns>""")
i = 0
for item in data:
i += 1
Response.Write( " <t%s>%s</t%s>" % ( i, item[0], i ) )
Response.Write( """
</Towns>
<Temperatures>""")
i = 0
for item in data:
i += 1
Response.Write( " <t%s>%s</t%s>" % ( i, item[1]["Temperature"], i ) )
Response.Write( """
</Temperatures>
<Icons>""")
i = 0
for item in data:
i += 1
Response.Write( " <t%s>%s</t%s>" % ( i, item[1]["Temperature"], i ) )
Response.Write( """
</Icons>
</Weather>
""")
%>