marcoloppo
asked on
How to change XML feeder date/time sort in this ASP script?
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
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.