Quantcast
Channel: Fórum ASP
Viewing all articles
Browse latest Browse all 1214

xml em conexao lenta + checar arquivo

$
0
0

Olá,

 

O que estou pretendendo fazer: um slideshow com texto e imagens vindos de um XML externo

 

Detalhes: conexão é lenta

 

o que penso

 

1 - preciso carregar um xml - ok

2 - preciso ler e passar o xml para cada item do slide - ok

3 - preciso checar, a cada 1 hora, se houve alterações no arquivo XML, através da tag <hash> do XML

4 - se houve alterações, preciso carregar o novo XML, caso contrário, o conteúdo continua o mesmo

5 - se ao tentar carregar o novo XML alterado, o processo falhar ou encontrar algum erro, tenho que continuar utilizando o mesmo

 

Eu já produzi a função abaixo, no entanto, não sei como integrar isso à página. No arquivo abaixo estou verificando uma diferença de tempo para leitura do arquivo, só que preciso fazer com que o ASP, a cada 1 hora cheque se teve alterações no arquivo, se não teve, fica do mesmo jeito, mas se houve alterações, ele tem que dar um novo reload na página (ou executar uma função, etc) para me permitir pegar o novo conteúdo e jogar na aplication.

<%
If DateDiff("h", Application("rss-html-time"), Now()) >= 1 then

  Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
  xmlDOM.async = False

  xmlDOM.setProperty "ServerHTTPRequest", True
  xmlDOM.Load("http://rss.uol.com.br/feed/copadomundo.xml")

  'verifica se está tudo correto
  	if xmlDOM.parseError.errorCode <> 0 then
		response.write "No momento a fonte de dados das notícias está fora do ar. -> "
		 Response.Write(objXML.parseError.reason)
   		 Response.Write(objXML.parseError.errorCode)
	else

		  'Get all of the <item> tags in the feed
		  Set itemList = xmlDOM.getElementsByTagName("item")
		  Set itemHash = xmlDOM.getElementsByTagName("category")
		  strHash = itemHash.item(0).text
		  
		  strHTML = strHTML & "<ul>"
		
		  'Iterate over each item
		  For Each item In itemList
		
			'Parse the item children
			For each child in item.childNodes
			  Select case lcase(child.nodeName)
				case "title"
				  titulo = child.text
				case "link"
				  link = child.text
				case "description"
				  descricao = child.text
			  End Select
			Next
		
			'Build the HTML for each bullet item
			strHTML = strHTML & "<li>"
			strHTML = strHTML & "<img src='arquivos/" & Server.HTMLEncode(link) & "'>"
			strHTML = strHTML & Server.HTMLEncode(titulo)
			'strHTML = strHTML & "</a>"
			strHTML = strHTML & "<br>"
			strHTML = strHTML & descricao
			strHTML = strHTML & "<br> "
			strHTML = strHTML & "</li>"
		  Next
		  strHTML = strHTML & "</ul>"
		
		  Set xmlDOM = Nothing
		  Set itemList = Nothing
		
		  Application.Lock
			Application("rss-html") = strHTML
			Application("rss-html-time") = Now()
			Application("hash") = strHash
		  Application.UnLock
	end if 'checa se tem erro - xmlDOM.parseError.errorCode <> 0
End If

Response.Write(Application("rss-html"))
response.write("<br><br>" & Application("rss-html-time"))
response.write("<br><br>" & Application("hash"))

Espero ter passado o que preciso.

 

Agradeço a ajuda...


Viewing all articles
Browse latest Browse all 1214

Trending Articles