Solved

How to change XML feeder date/time sort in this ASP script?

Posted on 2011-09-12
3
378 Views
Last Modified: 2012-05-12
Hi,

I have an ASP script to read a XML feeder and this script is not showing the news with the correct date/time order. The correct order is date/time descending, and it's showing the news in ascending order.

The XML source node dates are in correct order, the problem just happen when the script read this and show in HTML.

Bellow follows the the ASP scripts and XML

Anyone can help me to change this sort?

Tks
ASP Script:

<%
'Option Explicit	'Comentar esta linha caso não seja a 1ª include da chamada da página
Response.Buffer = True
Response.Charset = "ISO-8859-1"

'Configurações para visualizações de notícias
Const ngoXML_FOLDER = "d:\inetpub\wwwroot\rss\" 'Pasta para tratamento do arquivo XML de notícias e de controle de atualização
Const ngoITENS_PAGINA = 10 'Número de itens na consulta por páginas dinâmicas
Const ngoNUM_DIAS = 5 'Número de dias para armazenamento da lista de notícias
Const ngoMIN_UPDT = 10 'Número de minutos entre atualizações do XML

Function ngoGetList(NumItens, Page)
	Dim XMLNot, NodeList, Cont, ContAux, NumPags, LimMin, LimMax, LimAux
	ContAux = 0
	If NumItens = "" or Not IsNumeric(NumItens) Then NumItens = 0
	If Page = "" or Not IsNumeric(Page) Then Page = 0
	Set XMLNot = Server.CreateObject("MSXML2.DOMDocument")
	XMLNot.async = False
	If XMLNot.Load(ngoXML_FOLDER & "ngoNoticias.xml") Then
		ContAux = 0
		Set NodeList = XMLNot.DocumentElement.ChildNodes
		If NodeList.Length > 0 Then
			NumPags = Fix(NodeList.Length / ngoITENS_PAGINA) + ngoIIF(NodeList.Length Mod ngoITENS_PAGINA > 0, 1, 0)
			LimMax = NodeList.Length - 1
			If Page > 0	Then 'Limites para a lista dinâmica
				LimMax = LimMax - (Page - 1) * ngoITENS_PAGINA
				NumItens = ngoITENS_PAGINA
			End If
			LimMin = LimMax - NumItens
			'Mostra a lista de notícias - Edite o código abaixo para ajuste ao site
			If LimMin < 0 Then LimMin = 0 %>
<table summary="" width="100%" border="0" cellpadding="3" cellspacing="0"><%
			For Cont = LimMax to LimMin step -1 %>
<tr><td><b><img src=imagens/seta.gif> <% = ngoToDate(NodeList(Cont).ChildNodes(3).Text) %></b></td></tr><tr><td><a href="./ngoView.asp?codigo=<% = Trim(NodeList(Cont).ChildNodes(0).Text) %>"><% = Left(Trim(NodeList(Cont).ChildNodes(4).Text),27) %>...</a></td></tr><%
				ContAux = ContAux + 1
				If (CLng(NumItens) > 0) And (ContAux >= CLng(NumItens)) Then Exit For
			Next
			If (CLng(Page) > 0) And (CLng(Page) <= NumPags) Then %>
<tr>
	<td><% If CLng(Page) > 1 Then %><a href="ngoLista.asp?Pag=<% = CStr(CLng(Page) - 1) %>"><% = CStr(CLng(Page) - 1) %></a><% End If %></td>
	<td align="right"><% If CLng(Page) < NumPags Then %><a href="ngoLista.asp?Pag=<% = CStr(CLng(Page) + 1) %>"><% = CStr(CLng(Page) + 1) %></a><% End If %></td>
</tr><%
			End If %>
</table><br /><%
			Response.Flush
			Set NodeList = Nothing
		End If
	End If
	Set XMLNot = Nothing
	If ContAux <= 0 Then Response.Write("Não há notícias disponíveis no momento")
	If CLng(Page) <= 0 Then ngoUpdateXML 'Tenta atualizar o arquivo XML
End Function

Function ngoGetNews(ngoCodigo)	'Mostra as informações de uma notícia específica
	Dim XMLNot, NodeList, Node, ngoOK
	If ngoCodigo = "" or Not IsNumeric(ngoCodigo) Then ngoCodigo = 0
	'Set XMLNot = Server.CreateObject("MSXML2.DOMDocument.4.0")
	Set XMLNot = Server.CreateObject("MSXML2.DOMDocument")	
	XMLNot.async = False
	ngoOK = False
	If CLng(ngoCodigo) > 0 Then
		If XMLNot.Load(ngoXML_FOLDER & "ngoNoticias.xml") Then
			Set NodeList = XMLNot.DocumentElement.ChildNodes
			For Each Node in NodeList
				ngoOK = CLng(Node.ChildNodes(0).Text) = CLng(ngoCodigo)
				'Mostras a notícia - Edite o código abaixo para ajuste ao site
				If ngoOK Then %>
<div class=data><% = ngoToDate(Node.ChildNodes(3).Text) %></div>
<div class=titulo><% = Trim(Node.ChildNodes(4).Text) %></div><br />
<div class=noticia><% = Replace(Trim(Node.ChildNodes(5).Text), Chr(10), "<br/><br/>") %></div>
<%
					Exit For
				End If
			Next
			Set NodeList = Nothing
		End If
	End If
	Set XMLNot = Nothing
	If Not ngoOK Then Response.Write("Notícia não encontrada")
End Function

Function ngoUpdateXML()	'Checagem de necessidade de atualização do XML
	Dim FSO, F, UpdateFile, XMLNot, NodeList
	Set FSO = Server.CreateObject("Scripting.FileSystemObject")
	UpdateFile = Not FSO.FileExists(ngoXML_FOLDER & "ngoUpdate.txt")
	
	If Not UpdateFile Then	'Se já existe um arquivo anterior
		Set F = FSO.GetFile(ngoXML_FOLDER & "ngoUpdate.txt")
		UpdateFile = DateAdd("n",ngoMIN_UPDT,F.DateLastModified) < Now
		Set F = Nothing
	End If
	If UpdateFile Then
		'Atualização de arquivo de controle de atualização
		Set F = FSO.CreateTextFile(ngoXML_FOLDER & "ngoUpdate.txt", True)
		F.WriteLine(Now)
		F.Close
		Set F = Nothing
		'Obtenção do XML
	'Set XMLNot = Server.CreateObject("MSXML2.DOMDocument.4.0")
	Set XMLNot = Server.CreateObject("MSXML2.DOMDocument")	
		XMLNot.async = False
		XMLNot.setProperty "ServerHTTPRequest", True
		XMLNot.setProperty "SelectionLanguage", "XPath"
         'If XMLNot.Load("http://extranet.investimentosenoticias.com.br/servicos/ws/dr.asmx/NoticiasDiaPeriodo?usuario=ngo&senha=ngo&data_inicio=" & ngoWSDate(Date - ngoNUM_DIAS) & "&data_fim=" & ngoWSDate(Date + 1)) Then
         If XMLNot.Load("http://extranet.investimentosenoticias.com.br/servicos/ws/dr.asmx/NoticiasDia?usuario=ngo&senha=ngo&data_inicio=" & ngoWSDate(Date - ngoNUM_DIAS) & "&data_fim=" & ngoWSDate(Date + 1)) Then
			Set NodeList = XMLNot.DocumentElement.ChildNodes
			If NodeList.Length > 0 Then	XMLNot.Save(ngoXML_FOLDER & "ngoNoticias.xml")
		End If
		Set XMLNot = Nothing
	End If
	Set FSO = Nothing
End Function
	
Function ngoToDate(fromDate)	'Data do XML para Texto
	ngoToDate = Mid(fromDate,9,2) & "/" & Mid(fromDate,6,2) & "/" & Mid(fromDate,3,2) & " " & Replace(Mid(fromDate,12,5),":","h")
End Function

Function ngoWSDate(fromDate) 'Data para o WebService (de Date para Texto)
	'ngoWSDate = Right("0" & Day(fromDate),2) & "/" & Right("0" & Month(fromDate),2) & "/" & Year(fromDate)
	'ngoWSDate = Right("0" & Month(fromDate),2) & "/" & Right("0" & Day(fromDate),2) & "/" & Year(fromDate)
	ngoWSDate = Year(fromDate) & "/" & Right("0" & Month(fromDate),2) & "/" & Right("0" & Day(fromDate),2)
End Function

Function ngoIIF(Conditon, IfTrue, IfFalse)
	If Conditon Then
		ngoIIF = IfTrue
	Else
		ngoIIF = IfFalse
	End If
End Function 
%>

XML source example:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfNOTICIA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.investimentosenoticias.com.br/servicos">
	<NOTICIA>
		<COD_NOTICIA>1073276</COD_NOTICIA>
		<COD_EDITORIA>2690</COD_EDITORIA>
		<CHA_EDITORIA>Cambio                                            </CHA_EDITORIA>
		<DT_DATA>2011-09-12 16:32:00</DT_DATA>
		<CHA_TITLE>XX</CHA_TITLE>
		<CHA_TEXT>XXXXX</CHA_TEXT>
	</NOTICIA>
	<NOTICIA>
		<COD_NOTICIA>1073249</COD_NOTICIA>
		<COD_EDITORIA>2690</COD_EDITORIA>
		<CHA_EDITORIA>Cambio                                            </CHA_EDITORIA>
		<DT_DATA>2011-09-12 14:20:00</DT_DATA>
		<CHA_TITLE>XXX</CHA_TITLE>
		<CHA_TEXT>XXXXXX</CHA_TEXT>
	</NOTICIA>
	<NOTICIA>
		<COD_NOTICIA>1073248</COD_NOTICIA>
		<COD_EDITORIA>2690</COD_EDITORIA>
		<CHA_EDITORIA>Cambio                                            </CHA_EDITORIA>
		<DT_DATA>2011-09-12 14:19:00</DT_DATA>
		<CHA_TITLE>XXXX</CHA_TITLE>
		<CHA_TEXT>XXXXXXX</CHA_TEXT>
	</NOTICIA>
	<NOTICIA>
		<COD_NOTICIA>1073247</COD_NOTICIA>
		<COD_EDITORIA>2690</COD_EDITORIA>
		<CHA_EDITORIA>Cambio                                            </CHA_EDITORIA>
		<DT_DATA>2011-09-12 12:42:00</DT_DATA>
		<CHA_TITLE>XXX</CHA_TITLE>
		<CHA_TEXT>XXXXX</CHA_TEXT>
	</NOTICIA>
</ArrayOfNOTICIA>

Open in new window

0
Comment
Question by:marcoloppo
3 Comments
 
LVL 15

Accepted Solution

by:
pateljitu earned 500 total points
Comment Utility
Please change this line in your function ngoGetList

Change from this lime:
For Cont = LimMax to LimMin step -1
To this:
For Cont = LimMin to LimMax step +1
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now