The actual XML file
http://www.thevfamily.com/news/yh_xml/iraq.xmlASP Link
http://www.thevfamily.com/news/?cat=iraqI am just toying with XML and RSS Feeds. The majority of this ASP is from a moreover RSS example I found a while back. It works for the moreover feeds ok, but I want to make it work with yahoo now.
The ASP Link above works for the categories EXCEPT the Iraq one. The XML is grabbed and stored locally like the rest but I get a blank screen when I try to view the news via the asp, and an error if i try to view the xml directly;
-----XML ERROR-----
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
An invalid character was found in text content. Error processing resource '
http://www.thevfamily.com/news/yh_xml/iraq.xml'....
<description>OneWorld.net - BAGHDAD, Sep 7 (IPS)
-----XML ERROR-----
IF I open iraq.xml in txtpad, immediately following
<description>OneWorld.net - BAGHDAD, Sep 7 (IPS)
is a space, then a -, then another space = " - "
There are other -'s all through the other xml files. If I manually del the -, the Iraq news displays.
What on earth could be wrong with that ONE character???
Here is the code for the ASP and the XSL
-----ASP-----
<% Option Explicit
Dim sXMLDataDir, nHoursToRefresh, sCategory, pgStartTime
pgStartTime = Timer()
sXMLDataDir = Server.MapPath(".") & "/yh_xml/"
nHoursToRefresh = 1
sCategory = "topstories"
Function GetMoreoverXML(ByVal sCategory, ByVal sXMLDataFile)
Dim sChoice, sSource, objHTTP, sArticleList, sOut, oTS, oFSO, i
sSource= "
http://rss.news.yahoo.com/rss/" & sCategory
Set objHTTP = Server.CreateObject("Micro
soft.XMLHT
TP")
Set oFSO = Server.CreateObject("Scrip
ting.FileS
ystemObjec
t")
objHTTP.Open "GET", sSource, False
objHTTP.Send
sArticleList = objHTTP.ResponseBody
Set objHTTP = Nothing
sOut = ""
For i = 0 To UBound(sArticleList)
sOut = sOut & ChrW(AscW(Chr(AscB(MidB(sA
rticleList
, i + 1, 1)))))
Next
sOut = Replace (sOut, " encoding=""iso-8859-1"" ", "")
sOut = Replace (sOut, "<!-- generated by static php_rss_category -->", "")
sOut = Replace (sOut, """, """")
sOut = Replace (sOut, "&#36;", "$")
sOut = Replace (sOut, "&#151;", "-")
sOut = Replace (sOut, "&#8212;", "-")
sOut = Replace (sOut, "&#x2014;", "-")
Set oTS = oFSO.CreateTextFile(sXMLDa
taFile, True)
oTS.Write sOut
oTS.Close
Set oTS = Nothing
Set oFSO = Nothing
GetMoreoverXML = True
End Function
Function sShowNews(ByVal sXMLDataFile)
Dim objXML, objXSL
Set objXML = Server.CreateObject("Micro
soft.XMLDO
M")
Set objXSL = Server.CreateObject("Micro
soft.XMLDO
M")
objXSL.Async = False
objXML.Load(sXMLDataFile)
objXSL.Load(Server.MapPath
(".") & "/yahoo.xsl")
If (objXSL.ParseError.ErrorCo
de = 0) Then
sShowNews = objXML.TransformNode(objXS
L)
Else
sShowNews = "Error: " & objXSL.ParseError.Reason & "<br /> URL:" & objXSL.URL
End If
Set objXSL = Nothing
Set objXML = Nothing
End Function
Dim objFSO, fNewsFile, dLastSync, bGotFile, sXMLFile
If Request.QueryString("cat")
<> "" Then
sCategory = Request.QueryString("cat")
End If
bGotFile = False
Set objFSO = Server.CreateObject("Scrip
ting.FileS
ystemObjec
t")
sXMLFile = sXMLDataDir & LCase(sCategory) & ".xml"
If Not objFSO.FileExists(sXMLFile
) Then
bGotFile = GetMoreoverXML(sCategory, sXMLFile)
dLastSync = Now()
Else
Set fNewsFile = objFSO.GetFile(sXMLFile)
dLastSync = fNewsFile.DateLastModified
Set fNewsFile = Nothing
If DateDiff("h", dLastSync, Now()) >= nHoursToRefresh Then
bGotFile = GetMoreoverXML(sCategory, sXMLFile)
dLastSync = Now()
Else
bGotFile = True
End If
End If
Set objFSO = Nothing %>
<table align="center" border="0" width="660" cellpadding="10">
<tr><td valign="top"><h2><%=UCase(
sCategory)
%></h2>
<% If bGotFile = True Then
Response.Write "<p><small>Current: " & FormatDateTime(NOW(), vbLongDate) & " @ " & FormatDateTime(NOW(), vbLongTime) & "</small>" & vbNewLine
Response.Write "<br><small>Cached: " & FormatDateTime(dLastSync, vbLongDate) & " @ " & FormatDateTime(dLastSync, vbLongTime) & "</small></p>" & vbNewLine
Response.Write sShowNews(sXMLFile)
Else
Response.Write "<p><strong>There was an error retrieving the news feed.</strong></p>"
End If %>
</td><td valign="top" width="100" bgcolor="#F7F7F7">
<font size="2"><b>NEWS VIEW</b><BR>
<a href="?cat=topstories">Top
Stories</a><br>
<a href="?cat=world">World</a
><br>
<a href="?cat=us">US</a><br>
<a href="?cat=politics">Polit
ics</a><br
>
<a href="?cat=mideast">Mid East</a><br>
<a href="?cat=iraq">Iraq</a><
br>
<a href="?cat=sept11">Sept 11</a><br>
<a href="?cat=oped">Op Ed</a><br>
<p><font size="2"><b>XML VIEW</b><BR>
<a href="yh_xml/topstories.xm
l">Top Stories</a><br>
<a href="yh_xml/world.xml">Wo
rld</a><br
>
<a href="yh_xml/us.xml">US</a
><br>
<a href="yh_xml/politics.xml"
>Politics<
/a><br>
<a href="yh_xml/mideast.xml">
Mid East</a><br>
<a href="yh_xml/iraq.xml">Ira
q</a><br>
<a href="yh_xml/sept11.xml">S
ept 11</a><br>
<a href="yh_xml/oped.xml">Op Ed</a><br>
</font><%Response.Write "<p><font size=1 face=Verdana>Generated in: " &_
FormatNumber(Timer() - pgStartTime, 4) & "Sec</font><br>"%>
</td></tr></table>
-----ASP-----
-----XSL-----
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:for-each select="rss/channel/item">
<xsl:choose>
<xsl:when expr="childNumber(this) > 1000"></xsl:when>
<xsl:otherwise>
<p><font face="Arial"><strong><xsl:
value-of select="title"/> </strong>
<br /><font color="#660000" size="1"><xsl:value-of select="pubDate"/></font><
/font><br />
<font face=""><xsl:value-of select="description"/> ... </font>
<a><xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attri
bute>
<xsl:attribute name="target">_blank</xsl:
attribute>
more</a><b
r /></p>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-----XSL-----
I just don't understand what is wrong with that one character.
Ideas?
Start Free Trial