Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Attributes to HTML

Status
Not open for further replies.

Rsandoval

MIS
Jan 30, 2002
14
0
0
US
Hi...

I need to post weather information on my website. I receive a xml file every 30 mintues. I am having trouble extracting the attributes of the file so I can post just the temp and the sky information on my asp page. I have seen examples of extracting the elements but not the attrributes. Also I need the extraction to work in both IE and Netscape.

xml file:

<?xml version="1.0"?>
<WEATHER>
<WXWSOBS STATIONID="KTPA" TEMPERATURE="84" DEWPOINT="73" RELATIVEHUMIDITY="69" WINDSPEED="10" WINDDIRECTION="280" GUST="" PRESSURE="30.03" WEATHER="" SKY="Broken Clouds" CEILING="25000" VISIBILITY="10" HEATINDEX="91" WINDCHILL="84" SNOWDEPTH="" SIXHRMAX="88" TWENTYFOURHRMAX="" SIXHRMIN="79" TWENTYFOURHRMIN="" THREEHRPRECIP="" SIXHRPRECIP="Trace" TWENTYFOURHRPRECIP="" UPDATETIME="2004-7-26T18:00:00" />

</WEATHER>

Summary:
- pull xml data from a file
- Data needed:
- TEMPERATURE, SKY
- listed like: 84F, Broken Clouds

Thank for any help provided.

Roger
 
If you use an xsl on the client side or server side, you can extract the data with the following:

Code:
<?xml version='1.0' encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/WEATHER/WXWSOBS">
        <xsl:value-of select="@TEMPERATURE"/>F, <xsl:value-of select="@SKY"/>
    </xsl:template>
</xsl:stylesheet>

-jay
 
Hi Jay,

Sorry I did not reply. For some reason I never received an email that my post was responded to. Uh-oh.

Thanks for the feedback. I have been reading more on XML and I beelive this will work. I will give it a shot.
 
What you gave me worked perfectly. I also added some code to pull the data and put it into an asp file. Here is the code:

XML File (hcaaobs.xml):

Code:
<?xml version="1.0"?><WEATHER>
<WXWSOBS STATIONID="KTPA" TEMPERATURE="89" DEWPOINT="76" RELATIVEHUMIDITY="65" WINDSPEED="8" WINDDIRECTION="240" GUST="" PRESSURE="30.05" WEATHER="" SKY="Overcast" CEILING="4500" VISIBILITY="10" HEATINDEX="99" WINDCHILL="89" SNOWDEPTH="" SIXHRMAX="" TWENTYFOURHRMAX="" SIXHRMIN="" TWENTYFOURHRMIN="" THREEHRPRECIP="" SIXHRPRECIP="" TWENTYFOURHRPRECIP="" UPDATETIME="2004-8-17T19:00:00"/>
</WEATHER>

XSL File (weather.xsl)

Code:
<?xml version='1.0' encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/WEATHER/WXWSOBS">
        <xsl:value-of select="@TEMPERATURE"/>F, <xsl:value-of select="@SKY"/>
    </xsl:template>
</xsl:stylesheet>

ASP Code (weather.asp):
Code:
<%
Dim objXML
Dim objXSL
Dim strHTML

'Load the XML File
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load(Server.MapPath("hcaaobs.xml"))

'Load the XSL File
Set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = False
objXSL.load(Server.MapPath("weather.xsl"))

' Transform the XML file using the XSL stylesheet
strHTML = objXML.transformNode(objXSL)

Set objXML = Nothing
Set objXSL = Nothing

' Spit out the resulting HTML... the data comes from the
' .xml file, but the formatting of the results depends
' completely upon the .xsl file.
Response.Write strHTML
%>

Hope this helps others. Check out the TampaAirport.com redesign, Monday, August 23, 2004!! Your xsl has helped!!

Thanks [thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top