Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Bart

IE não lê arquivo xml, mas FF sim.

Recommended Posts

Criei um arquivo ASP que lê um feed xml (no meu exemplo o do G1), e escreve exatamente o mesmo código XML lido na página.

O problema é que o XML escrito pelo ASP não consegue ser interpretado corretamente pelo Internet Explorer.

Ele acusa erro em um nó que contém uma palavra com ACENTO ("Notícias").

O problema é que se você pegar o código fonte do XML gerado e que o Internet Explorer acusa erro, copiar seu conteúdo, salvar em um arquivo XML e abrir no Internet Explorer ele lê.

Ou seja, o mesmo código quando gerado pelo ASP dá erro, mas se você copiar o código gerado, colar em um arquivo e abrir no IE, funciona.

 

Porque isso?

 

Links dos arquivos:

ASP gerando o XML (e dando erro): http://www.brninternet.com/testes/feedComErro.asp

Código colado na mão (funcionando): http://www.brninternet.com/testes/feedSemErro.asp

 

Segue abaixo o código da minha página ASP que gera o XML.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%Option Explicit%>
<%Response.ContentType="application/xml"%>
<%Response.Charset="ISO-8859-1"%>
<%
	function getStrXml(url)
		'Esta sub retorna a string do XML lido
		Dim objSrvHTTP, strXML, objXML, raiz, i, channel, itens
	
	
		'Instancia o objeto HttpRequest.
		Set objSrvHTTP = Server.CreateObject("MSXML2.XMLHTTP.3.0")
		
		'Informe o método e a URL a ser capturada
		objSrvHTTP.open "GET", url, false
		
		'Com o método setRequestHeader informamos o cabeçalho HTTP
		objSrvHTTP.setRequestHeader "Content-Type", "text/xml"

		'O método Send envia a solicitação HTTP e exibe o conteúdo da página
		objSrvHTTP.Send()
		
		'Amazenamos o resultado na variável strXML
		strXML = objSrvHTTP.ResponseXML.xml
		
		'Instancia o objeto XMLDOM
		Set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0") 
		'Indicamos que o download em segundo plano não é permitido
		objXML.async = false

		'O método loadXML carrega parte do código, sem ter o documento XML
		objXML.loadXML(strXML)
		
		'Verifica possíveis erros com o método parseError
		if objXML.ParseError.errorCode <> 0 then
			response.write "Código do erro: " & objXML.parseError.errorCode & "<br>"
			response.write "Posição no arquivo: " & objXML.parseError.filepos & "<br>"
			response.write "Linha: " & objXML.parseError.line & "<br>"
			response.write "Posição na linha: " & objXML.parseError.linepos & "<br>"
			response.write "Descrição: " & objXML.parseError.reason & "<br>"
			response.write "Texto que causa o erro: " & objXML.parseError.srcText & "<br>"
			response.write "Url do arquivo com problemas: " & objXML.parseError.url
		end if
		
		'Destruíndo os objetos
		Set objXML = Nothing
		Set objSrvHTTP = Nothing

		getStrXml = strXML
	end function

	Response.Write(getStrXml("http://g1.globo.com/Rss2/0,,AS0-5597,00.xml"))
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

como default o XML é UTF, nao use ISO e retire o CODEPAGE

 

tente assim:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<body>
<%
Response.ContentType="text/html"
Response.Charset="UTF-8"

	function getStrXml(url)
		'Esta sub retorna a string do XML lido
		Dim objSrvHTTP, strXML, objXML, raiz, i, channel, itens
	
	
		'Instancia o objeto HttpRequest.
		Set objSrvHTTP = Server.CreateObject("MSXML2.XMLHTTP.3.0")
		
		'Informe o método e a URL a ser capturada
		objSrvHTTP.open "GET", url, false
		
		'Com o método setRequestHeader informamos o cabeçalho HTTP
		objSrvHTTP.setRequestHeader "Content-Type", "text/xml"

		'O método Send envia a solicitação HTTP e exibe o conteúdo da página
		objSrvHTTP.Send()
		
		'Amazenamos o resultado na variável strXML
		strXML = objSrvHTTP.ResponseXML.xml
		
		'Instancia o objeto XMLDOM
		Set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0") 
		'Indicamos que o download em segundo plano não é permitido
		objXML.async = false

		'O método loadXML carrega parte do código, sem ter o documento XML
		objXML.loadXML(strXML)
		
		'Verifica possíveis erros com o método parseError
		if objXML.ParseError.errorCode <> 0 then
			response.write "Código do erro: " & objXML.parseError.errorCode & "<br>"
			response.write "Posição no arquivo: " & objXML.parseError.filepos & "<br>"
			response.write "Linha: " & objXML.parseError.line & "<br>"
			response.write "Posição na linha: " & objXML.parseError.linepos & "<br>"
			response.write "Descrição: " & objXML.parseError.reason & "<br>"
			response.write "Texto que causa o erro: " & objXML.parseError.srcText & "<br>"
			response.write "Url do arquivo com problemas: " & objXML.parseError.url
		end if
		
		'Destruíndo os objetos
		Set objXML = Nothing
		Set objSrvHTTP = Nothing

		getStrXml = strXML
	end function

	Response.Write(getStrXml("http://g1.globo.com/Rss2/0,,AS0-5597,00.xml"))
%>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Fala cara, beleza?

A saída que preciso é XML e não HTML.

Se eu alterar o código como você sugeriu não terei mais um XML e sim um arquivo HTML.

Nesse caso, não me serve mais.

 

Mesmo assim, valew.

 

como default o XML é UTF, nao use ISO e retire o CODEPAGE

 

tente assim:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<body>
<%
Response.ContentType="text/html"
Response.Charset="UTF-8"

	function getStrXml(url)
		'Esta sub retorna a string do XML lido
		Dim objSrvHTTP, strXML, objXML, raiz, i, channel, itens
	
	
		'Instancia o objeto HttpRequest.
		Set objSrvHTTP = Server.CreateObject("MSXML2.XMLHTTP.3.0")
		
		'Informe o método e a URL a ser capturada
		objSrvHTTP.open "GET", url, false
		
		'Com o método setRequestHeader informamos o cabeçalho HTTP
		objSrvHTTP.setRequestHeader "Content-Type", "text/xml"

		'O método Send envia a solicitação HTTP e exibe o conteúdo da página
		objSrvHTTP.Send()
		
		'Amazenamos o resultado na variável strXML
		strXML = objSrvHTTP.ResponseXML.xml
		
		'Instancia o objeto XMLDOM
		Set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0") 
		'Indicamos que o download em segundo plano não é permitido
		objXML.async = false

		'O método loadXML carrega parte do código, sem ter o documento XML
		objXML.loadXML(strXML)
		
		'Verifica possíveis erros com o método parseError
		if objXML.ParseError.errorCode <> 0 then
			response.write "Código do erro: " & objXML.parseError.errorCode & "<br>"
			response.write "Posição no arquivo: " & objXML.parseError.filepos & "<br>"
			response.write "Linha: " & objXML.parseError.line & "<br>"
			response.write "Posição na linha: " & objXML.parseError.linepos & "<br>"
			response.write "Descrição: " & objXML.parseError.reason & "<br>"
			response.write "Texto que causa o erro: " & objXML.parseError.srcText & "<br>"
			response.write "Url do arquivo com problemas: " & objXML.parseError.url
		end if
		
		'Destruíndo os objetos
		Set objXML = Nothing
		Set objSrvHTTP = Nothing

		getStrXml = strXML
	end function

	Response.Write(getStrXml("http://g1.globo.com/Rss2/0,,AS0-5597,00.xml"))
%>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

da uma olhada nesta classe para leitura de RSS

 

classe:

<%Option Explicit%>
<script language="vbscript" runat="server">
'*******************************************************
'LEITURA DE RSS 
'*******************************************************
Class LeitorRSS
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_MensagemErro
	Private a_Channel
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get MensagemErro
		MensagemErro = a_MensagemErro
	End Property
	Private Property Let MensagemErro(ByVal p_objXmlParseerror)
		a_MensagemErro = Server.HTMLEncode(p_objXmlParseerror.srcText) & "<br>" & p_objXmlParseerror.Reason & " (Line " & p_objXmlParseerror.Line & ", Column " & p_objXmlParseerror.Linepos  & ")"
	End Property
	Public Property Get RSSChannel
		Set RSSChannel = a_Channel
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
		'Inicializando o objeto Channel
		Set a_Channel = New Channel
	End Sub
	Private Sub Class_Terminate()
		'Destruindo o objeto Channel
		Set a_Channel = Nothing
	End Sub
		
	'-----------------------------------------------------
	'MÉTODOS DA CLASSE
	'-----------------------------------------------------
	'-----------------------------------------------------
	'Funcao: ReadURL(ByVal strURL)
	'Sinopse: Faz a Leitura da URL contendo o RSS
	'		  e carrega os dados do formato XML nos
	'		  objetos.
	'Parametro:
	'	   strURL: URL contendo o conteúdo XML-RSS 2.0
	'Retorno: Boolean
	'-----------------------------------------------------
	Public Function ReadURL(ByVal strURL)
		'Declaração
		Dim objXml
		Dim objXmlChannels
		Dim objXmlChannelsNos
		Dim objXmlNode
		Dim objXmlNode2
		Dim objXmlNode3
		Dim objXmlSubNode
		Dim objXmlSubNode2
		Dim objXmlSubNodedes
		Dim objXmlSubNodede
		Dim objXmlHttp
		Dim objChannelItem
		Dim XmlDoc
		Dim i, j, t
		'Inicialização dos objetos
		Set objXmlHttp	= Server.CreateObject("MSXML2.XMLHTTP")
		Set objXml		= Server.CreateObject("MSXML2.DOMDOCUMENT")
				
		'Resgatando os dados do XML via Http
		objXMLHttp.Open "GET", strURL, False
		Call objXMLHttp.Send()
		XmlDoc	= BinaryToString(objXmlHttp.ResponseBody)

		'Abrindo o XML
		objXml.ValidateOnParse	= True
		objXml.Async			= False
		objXml.LoadXML(XmlDoc)
		'Verificando se é um XML válido.
		If objXml.ParseError.ErrorCode <> 0 Then
			MensagemErro = objXml.ParseError
			'Destruindo os objetos
			Set objXmlHttp	= Nothing
			Set objXml		= Nothing
			'Saindo da função
			ReadURL			= False
			Exit Function
		End If
		
		'......................................................
		'Populando os dados
		'......................................................
		'CHANNEL
		Set objXmlChannels = objXml.getElementsByTagName("channel")
		Set objXmlChannelsNos = objXmlChannels.Item(0).childNodes

		'Looping nos nós da channel
		For i = 0 To objXmlChannelsNos.Length-1
			Set objXmlNode = objXmlChannelsNos.Item(i)

			Select Case Lcase(objXmlNode.TagName)
				Case "title"
					a_Channel.Title					= objXmlNode.Text
				Case "link"
					a_Channel.Link					= objXmlNode.Text
				Case "description"
					a_Channel.Description			= objXmlNode.Text
				Case "language"
					a_Channel.Language				= objXmlNode.Text
				Case "copyright"
					a_Channel.Copyright				= objXmlNode.Text
				Case "managingeditor"
					a_Channel.ManagingEditor		= objXmlNode.Text
				Case "webmaster"
					a_Channel.WebMaster				= objXmlNode.Text
				Case "pubdate"
					a_Channel.PubDate				= objXmlNode.Text
				Case "lastbuilddate"
					a_Channel.LastBuildDate			= objXmlNode.Text
				Case "lastbuilddate"
					a_Channel.LastBuildDate			= objXmlNode.Text
				Case "category"
					a_Channel.Category				= objXmlNode.Text
				Case "generator"
					a_Channel.Generator				= objXmlNode.Text
				Case "cloud"
					'Resgatando os Sub-elementos do nó cloud
					Set objXmlSubNode				= objXmlNode.childNodes
					For j = 0 To objXmlSubNode.Length-1
						Set objXmlNode2 = objXmlSubNode.Item(j)
						Select Case Lcase(objXmlNode2.tagName)
							Case "domain"
							a_Channel.Cloud.Domain				= objXmlNode2.Text
							Case "port"
							a_Channel.Cloud.Port				= objXmlNode2.Text
							Case "path"
							a_Channel.Cloud.Path				= objXmlNode2.Text
							Case "registerprocedure"
							a_Channel.Cloud.RegisterProcedure	= objXmlNode2.Text
							Case "protocol"
							a_Channel.Cloud.Protocol			= objXmlNode2.Text
						End Select
						Set objXmlNode2 = Nothing
					Next
				Case "ttl"
					a_Channel.Ttl	= objXmlNode.Text
				Case "image"
					'Resgatando os Sub-elementos do nó image
					Set objXmlSubNode				= objXmlNode.childNodes
					For j = 0 To objXmlSubNode.Length-1
						Set objXmlNode2 = objXmlSubNode.Item(j)
						Select Case Lcase(objXmlNode2.tagName)
							Case "url"
							a_Channel.Image.Url		= objXmlNode2.Text
							Case "title"
							a_Channel.Image.Title	= objXmlNode2.Text
							Case "link"
							a_Channel.Image.Link	= objXmlNode2.Text
							Case "width"
							a_Channel.Image.Width	= objXmlNode2.Text
							Case "height"
							a_Channel.Image.Height	= objXmlNode2.Text
						End Select
						Set objXmlNode2 = Nothing
					Next
				Case "textinput"
					'Resgatando os Sub-elementos do nó textinput
					Set objXmlSubNode				= objXmlNode.childNodes
					For j = 0 To objXmlSubNode.Length-1
						Set objXmlNode2 = objXmlSubNode.Item(j)
						Select Case Lcase(objXmlNode2.tagName)
							Case "title"
							a_Channel.TextInput.Title		= objXmlNode2.Text
							Case "description"
							a_Channel.TextInput.Description	= objXmlNode2.Text
							Case "name"
							a_Channel.TextInput.Name		= objXmlNode2.Text
							Case "link"
							a_Channel.TextInput.Link		= objXmlNode2.Text
						End Select
						Set objXmlNode2 = Nothing
					Next
				Case "skiphours"
					a_Channel.SkipHours		= objXmlNode.Text
				Case "skipdays"
					a_Channel.SkipDays		= objXmlNode.Text
				Case "item"
					'Resgatando os Sub-elementos do nó item
					Set objXmlSubNode	= objXmlNode.childNodes
					Set objChannelItem	= New ChannelItem
					For j = 0 To objXmlSubNode.Length-1
						Set objXmlNode2		= objXmlSubNode.Item(j)
						Select Case Lcase(objXmlNode2.tagName)
							Case "title"
							objChannelItem.Title			= objXmlNode2.Text
							Case "link"
							objChannelItem.Link				= objXmlNode2.Text
							Case "description"
							objChannelItem.Description		= objXmlNode2.Text
							Case "author"
							objChannelItem.Author			= objXmlNode2.Text
							Case "category"
								'Resgatando os Sub-elementos do nó item/category
								Set objXmlSubNode2	= objXmlNode2.childNodes
								For t = 0 To objXmlSubNode2.Length-1
									Set objXmlNode3		= objXmlSubNode2.Item(t)
									Select Case Lcase(objXmlNode3.tagName)
										Case "description"
											objChannelItem.Category.Description	= objXmlNode3.Text
										Case "domain"
											objChannelItem.Category.Domain		= objXmlNode3.Text
									End Select
									Set objXmlNode3		= Nothing
								Next
								Set objXmlSubNode2		= Nothing
							Case "comments"
							objChannelItem.Comments			= objXmlNode2.Text
							Case "enclosure"
								'Resgatando os Sub-elementos do nó item/enclosure
								Set objXmlSubNode2	= objXmlNode2.childNodes
								For t = 0 To objXmlSubNode2.Length-1
									Set objXmlNode3		= objXmlSubNode2.Item(t)
									Select Case Lcase(objXmlNode3.tagName)
										Case "url"
											objChannelItem.Enclosure.Url	= objXmlNode3.Text
										Case "length"
											objChannelItem.Enclosure.Length	= objXmlNode3.Text
										Case "etype"
											objChannelItem.Enclosure.EType	= objXmlNode3.Text
									End Select
									Set objXmlNode3		= Nothing
								Next
								Set objXmlSubNode2		= Nothing
							Case "guid"
								'Resgatando os Sub-elementos do nó item/guid
								Set objXmlSubNode2	= objXmlNode2.childNodes
								For t = 0 To objXmlSubNode2.Length-1
									Set objXmlNode3		= objXmlSubNode2.Item(t)
									Select Case Lcase(objXmlNode3.tagName)
										Case "description"
											objChannelItem.Guid.Description	= objXmlNode3.Text
										Case "ispermalink"
											objChannelItem.Guid.IsPermaLink	= objXmlNode3.Text
									End Select
									Set objXmlNode3		= Nothing
								Next
								Set objXmlSubNode2		= Nothing
							Case "pubdate"
							objChannelItem.PubDate			= objXmlNode2.Text
							Case "source"
								'Resgatando os Sub-elementos do nó item/source
								Set objXmlSubNode2	= objXmlNode2.childNodes
								For t = 0 To objXmlSubNode2.Length-1
									Set objXmlNode3		= objXmlSubNode2.Item(t)
									Select Case Lcase(objXmlNode3.tagName)
										Case "description"
											objChannelItem.Source.Description	= objXmlNode3.Text
										Case "url"
											objChannelItem.Source.Url			= objXmlNode3.Text
									End Select
									Set objXmlNode3		= Nothing
								Next
								Set objXmlSubNode2		= Nothing
						End Select
						Set objXmlNode2 = Nothing
					Next
					'Adicionando o Item na Coleção
					Call a_Channel.AddItem(objChannelItem)
					Set objChannelItem	= Nothing
			End Select
			Set objXmlNode = Nothing
		Next
		'......................................................
		
		'Destruindo os objetos
		Set objXml		= Nothing
		Set objXmlHttp	= Nothing
		
		'Retornando a função
		ReadURL = True
	End Function
	
	Public Function BinaryToString(xBinary)
		Dim Binary
		Dim RS, LBinary
		If VarType(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary
		Const adLongVarChar = 201
		Set RS = CreateObject("ADODB.Recordset")
		LBinary = LenB(Binary)
		If LBinary>0 Then
			RS.Fields.Append "mBinary", adLongVarChar, LBinary
			RS.Open
			RS.AddNew
			RS("mBinary").AppendChunk Binary 
			RS.Update
			BinaryToString = RS("mBinary")
		Else
			BinaryToString = ""
		End If
		Set RS = Nothing
	End Function

	Public Function MultiByteToBinary(MultiByte)
		Dim RS, LMultiByte, Binary
		Const adLongVarBinary = 205
		Set RS = CreateObject("ADODB.Recordset")
		LMultiByte = LenB(MultiByte)
		If LMultiByte>0 Then
			RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
			RS.Open
			RS.AddNew
			RS("mBinary").AppendChunk MultiByte & ChrB(0)
			RS.Update
			Binary = RS("mBinary").GetChunk(LMultiByte)
		End If
		Set RS = Nothing
		MultiByteToBinary = Binary
	End Function
	
End Class
'*******************************************************

'*******************************************************
'CLASSE CHANNEL
'*******************************************************
Class Channel
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Title
	Private a_Link
	Private a_Description
	'Opcionais
	Private a_Language
	Private a_Copyright	
	Private a_ManagingEditor
	Private a_WebMaster
	Private a_PubDate
	Private a_LastBuildDate	
	Private a_Category
	Private a_Generator
	Private a_Docs
	Private a_Cloud	
	Private a_Ttl						
	Private a_Image	
	Private a_TextInput	
	Private a_SkipHours
	Private a_SkipDays	
	Private a_Item
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Default Property Get Title
		Title = a_Title
	End Property
	Public Property Let Title(ByVal p_Title)
		a_Title = p_Title
	End Property

	Public Property Get Link
		Link = a_Link
	End Property
	Public Property Let Link(ByVal p_Link)
		a_Link = p_Link
	End Property

	Public Property Get Description
		Description = a_Description
	End Property
	Public Property Let Description(ByVal p_Description)
		a_Description = p_Description
	End Property

	Public Property Get Language
		Language = a_Language
	End Property
	Public Property Let Language(ByVal p_Language)
		a_Language = p_Language
	End Property
	
	Public Property Get Copyright
		Copyright = a_Copyright
	End Property
	Public Property Let Copyright(ByVal p_Copyright)
		a_Copyright = p_Copyright
	End Property
	
	Public Property Get ManagingEditor
		ManagingEditor = a_ManagingEditor
	End Property
	Public Property Let ManagingEditor(ByVal p_ManagingEditor)
		a_ManagingEditor = p_ManagingEditor
	End Property
	
	Public Property Get WebMaster
		WebMaster = a_WebMaster
	End Property
	Public Property Let WebMaster(ByVal p_WebMaster)
		a_WebMaster = p_WebMaster
	End Property
	
	Public Property Get PubDate
		PubDate = a_PubDate
	End Property
	Public Property Let PubDate(ByVal p_PubDate)
		a_PubDate = p_PubDate
	End Property

	Public Property Get LastBuildDate
		LastBuildDate = a_LastBuildDate
	End Property
	Public Property Let LastBuildDate(ByVal p_LastBuildDate)
		a_LastBuildDate = p_LastBuildDate
	End Property
	
	Public Property Get Category
		Category = a_Category
	End Property
	Public Property Let Category(ByVal p_Category)
		a_Category = p_Category
	End Property
	
	Public Property Get Generator
		Generator = a_Generator
	End Property
	Public Property Let Generator(ByVal p_Generator)
		a_Generator = p_Generator
	End Property
	
	Public Property Get Docs
		Docs = a_Docs
	End Property
	Public Property Let Docs(ByVal p_Docs)
		a_Docs = p_Docs
	End Property
	
	Public Property Get Cloud
		Set Cloud = a_Cloud
	End Property
	
	Public Property Get Ttl
		Ttl = a_Ttl
	End Property
	Public Property Let Ttl(ByVal p_Ttl)
		a_Ttl = p_Ttl
	End Property
	
	Public Property Get Image
		Set Image = a_Image
	End Property
	
	Public Property Get TextInput
		Set TextInput = a_TextInput
	End Property
	
	Public Property Get SkipHours
		SkipHours = a_SkipHours
	End Property
	Public Property Let SkipHours(ByVal p_SkipHours)
		a_SkipHours = p_SkipHours
	End Property
	
	Public Property Get SkipDays
		SkipDays = a_SkipDays
	End Property
	Public Property Let SkipDays(ByVal p_SkipDays)
		a_SkipDays = p_SkipDays
	End Property
	
	Public Property Get Item
		Set Item = a_Item
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
		'Inicializando as propriedades que são multivaloradas
		Set a_Image			= New ChannelImage
		Set a_Cloud			= New ChannelCloud
		Set a_TextInput		= New ChannelTextInput
		Set a_Item			= Server.CreateObject("Scripting.Dictionary")
	End Sub
	Private Sub Class_Terminate()
		'Destruindo as propriedades que são multivaloradas
		Set a_Item			= Nothing
		Set a_TextInput		= Nothing
		Set a_Cloud			= Nothing
		Set a_Image			= Nothing
	End Sub
	
	'-----------------------------------------------------
	'MÉTODOS DA CLASSE
	'-----------------------------------------------------
	'-----------------------------------------------------
	'Funcao: AddItem(ByVal p_objChannelItem)
	'Sinopse: Adiciona um novo Item na Coleção de Itens
	'Parametro:
	'	   objChannelItem: Objeto com os Itens
	'Retorno: Boolean
	'-----------------------------------------------------
	Public Function AddItem(ByVal p_objChannelItem)
		If TypeName(p_objChannelItem) = "ChannelItem" Then
			Call a_Item.Add(a_Item.Count+1, p_objChannelItem)
			AddItem = True
		Else
			AddItem = False
		End If
	End Function
End Class
'*******************************************************

'*******************************************************
'CLASSE IMAGE DO ELEMENTO CHANNEL
'*******************************************************
Class ChannelImage
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Url
	Private a_Title
	Private a_Link
	'Opcionais
	Private a_Width
	Private a_Height
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Url
		Url = a_Url
	End Property
	Public Property Let Url(ByVal p_Url)
		a_Url = p_Url
	End Property
	
	Public Property Get Title
		Title = a_Title
	End Property
	Public Property Let Title(ByVal p_Title)
		a_Title = p_Title
	End Property
	
	Public Property Get Link
		Link = a_Link
	End Property
	Public Property Let Link(ByVal p_Link)
		a_Link = p_Link
	End Property
	
	Public Property Get Width
		Width = a_Width
	End Property
	Public Property Let Width(ByVal p_Width)
		If p_Width > 144 Then
			p_Width = 144
		End If
		a_Width = p_Width
	End Property
	
	Public Property Get Height
		Height = a_Height
	End Property
	Public Property Let Height(ByVal p_Height)
		If p_Height > 400 Then
			p_Height = 400
		End If
		a_Height = p_Height
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
		'Valores Default
		a_Width		= 88
		a_Height	= 31
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE CLOUD DO ELEMENTO CHANNEL
'*******************************************************
Class ChannelCloud
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Domain
	Private a_Port
	Private a_Path
	Private a_RegisterProcedure
	Private a_Protocol
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Domain
		Domain = a_Domain
	End Property
	Public Property Let Domain(ByVal p_Domain)
		a_Domain = p_Domain
	End Property
	
	Public Property Get Port
		Port = a_Port
	End Property
	Public Property Let Port(ByVal p_Port)
		a_Port = p_Port
	End Property
	
	Public Property Get Path
		Path = a_Path
	End Property
	Public Property Let Path(ByVal p_Path)
		a_Path = p_Path
	End Property
	
	Public Property Get RegisterProcedure
		RegisterProcedure = a_RegisterProcedure
	End Property
	Public Property Let RegisterProcedure(ByVal p_RegisterProcedure)
		a_RegisterProcedure = p_RegisterProcedure
	End Property
	
	Public Property Get Protocol
		Protocol = a_Protocol
	End Property
	Public Property Let Protocol(ByVal p_Protocol)
		a_Protocol = p_Protocol
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE TEXTINPUT DO ELEMENTO CHANNEL
'*******************************************************
Class ChannelTextInput
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Title
	Private a_Description
	Private a_Name
	Private a_Link
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Title
		Title = a_Title
	End Property
	Public Property Let Title(ByVal p_Title)
		a_Title = p_Title
	End Property
	
	Public Property Get Description
		Description = a_Description
	End Property
	Public Property Let Description(ByVal p_Description)
		a_Description = p_Description
	End Property
	
	Public Property Get Name
		Name = a_Name
	End Property
	Public Property Let Name(ByVal p_Name)
		a_Name = p_Name
	End Property
	
	Public Property Get Link
		Link = a_Link
	End Property
	Public Property Let Link(ByVal p_Link)
		a_Link = p_Link
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE ITEM DO ELEMENTO CHANNEL
'*******************************************************
Class ChannelItem
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Title
	Private a_Link
	Private a_Description
	Private a_Author
	Private a_Category
	Private a_Comments
	Private a_Enclosure
	Private a_Guid
	Private a_PubDate
	Private a_Source
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Title
		Title = a_Title
	End Property
	Public Property Let Title(ByVal p_Title)
		a_Title = p_Title
	End Property
	
	Public Property Get Link
		Link = a_Link
	End Property
	Public Property Let Link(ByVal p_Link)
		a_Link = p_Link
	End Property
	
	Public Property Get Description
		Description = a_Description
	End Property
	Public Property Let Description(ByVal p_Description)
		a_Description = p_Description
	End Property
	
	Public Property Get Author
		Author = a_Author
	End Property
	Public Property Let Author(ByVal p_Author)
		a_Author = p_Author
	End Property
	
	Public Property Get Category
		Set Category = a_Category
	End Property
	
	Public Property Get Comments
		Comments = a_Comments
	End Property
	Public Property Let Comments(ByVal p_Comments)
		a_Comments = p_Comments
	End Property
	
	Public Property Get Enclosure
		Set Enclosure = a_Enclosure
	End Property
	
	Public Property Get Guid
		Set Guid = a_Guid
	End Property
	
	Public Property Get PubDate
		PubDate = a_PubDate
	End Property
	Public Property Let PubDate(ByVal p_PubDate)
		a_PubDate = p_PubDate
	End Property
	
	Public Property Get Source
		Set Source = a_Source
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
		'Inicializando as propriedades que são multivaloradas
		Set a_Category		= New ItemCategory
		Set a_Enclosure		= New ItemEnclosure
		Set a_Guid			= New ItemGuid
		Set a_Source		= New ItemSource
	End Sub
	Private Sub Class_Terminate()
		'Destruindo as propriedades que são multivaloradas
		Set a_Category		= Nothing
		Set a_Enclosure		= Nothing
		Set a_Guid			= Nothing
		Set a_Source		= Nothing
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE CATEGORY DO ELEMENTO ITEM
'*******************************************************
Class ItemCategory
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Description
	'Opcionais
	Private a_Domain
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Description
		Description = a_Description
	End Property
	Public Property Let Description(ByVal p_Description)
		a_Description = p_Description
	End Property
	
	Public Property Get Domain
		Domain = a_Domain
	End Property
	Public Property Let Domain(ByVal p_Domain)
		a_Domain = p_Domain
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE ENCLOSURE DO ELEMENTO ITEM
'*******************************************************
Class ItemEnclosure
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Url
	Private a_Length
	Private a_EType
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Url
		Url = a_Url
	End Property
	Public Property Let Url(ByVal p_Url)
		a_Url = p_Url
	End Property
	
	Public Property Get Length
		Length = a_Length
	End Property
	Public Property Let Length(ByVal p_Length)
		a_Length = p_Length
	End Property
	
	Public Property Get EType
		EType = a_EType
	End Property
	Public Property Let EType(ByVal p_EType)
		a_EType = p_EType
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE GUID DO ELEMENTO ITEM
'*******************************************************
Class ItemGuid
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Description
	'Opcionais
	Private a_IsPermaLink
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Description
		Description = a_Description
	End Property
	Public Property Let Description(ByVal p_Description)
		a_Description = p_Description
	End Property
	
	Public Property Get IsPermaLink
		IsPermaLink = a_IsPermaLink
	End Property
	Public Property Let IsPermaLink(ByVal p_IsPermaLink)
		a_IsPermaLink = p_IsPermaLink
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
		'Valores Default
		a_IsPermaLink = True
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************

'*******************************************************
'CLASSE SOURCE DO ELEMENTO ITEM
'*******************************************************
Class ItemSource
	'-----------------------------------------------------
	'ATRIBUTOS DA CLASSE
	'-----------------------------------------------------
	'Obrigatórios
	Private a_Url
	Private a_Description
	
	'-----------------------------------------------------
	'PROPRIEDADES DA CLASSE
	'-----------------------------------------------------
	Public Property Get Url
		Url = a_Url
	End Property
	Public Property Let Url(ByVal p_Url)
		a_Url = p_Url
	End Property
	
	Public Property Get Description
		Description = a_Description
	End Property
	Public Property Let Description(ByVal p_Description)
		a_Description = p_Description
	End Property
	
	'-----------------------------------------------------
	'MÉTODOS DE CRIAÇÃO E DESTRUIÇÃO DA CLASSE
	'-----------------------------------------------------
	Private Sub Class_Initialize()
	End Sub
	Private Sub Class_Terminate()
	End Sub
End Class
'*******************************************************
</script>

Usando a classe:

<!-- #include file="Classe_LeitorRSS.asp" -->
<%
Dim objLeitorRSS
Dim Mensagem
Dim Cont
Dim objRSSChannel
Set objLeitorRSS	= New LeitorRSS
Mensagem			= ""
If Not objLeitorRSS.ReadURL("http://rss.terra.com.br/0,,EI4795,00.xml") Then
	Mensagem = objLeitorRSS.MensagemErro
Else
	Set objRSSChannel = New Channel
	Set objRSSChannel = objLeitorRSS.RSSChannel
End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Leitor RSS 2.0</title>
</head>
<body>
<center>
<table border="0" cellpadding="0" bgcolor="#000000" cellspacing="1" width="500" height="100%"><tr><td valign="top">

	<table border="0" cellpadding="0" bgcolor="#ffffff" cellspacing="0" width="500" height="100%">
	<%If Not Mensagem = "" Then%>
		<tr><td height="100%" valign="top"><font face="verdana" size="2" color="#ff8500"><%=Mensagem%></font></td></tr>
	<%Else%>
		<tr bgcolor="#000000">
			<td align="center" valign="middle" height="35" colspan="2">
				<strong><a href="<%=objRSSChannel.Link%>"><font face="verdana" size="2" color="#ff8500"><%=objRSSChannel.Title%></font></a></strong>
				<br>
				<font face="verdana" size="1" color="#ff8500"><%=objRSSChannel.PubDate%></font>
			</td>
		<tr>
		<tr bgcolor="#f0f0f0">
			<td valign="top" height="1%">
				<a href="<%=objRSSChannel.Image.Link%>"><img src="<%=objRSSChannel.Image.Url%>" alt="<%=objRSSChannel.Image.Title%>" border="0" align=baseline></a>
			</td>
			<td align="left" valign="top" height="10">
				<font face="verdana" size="2" color="#000000"><%=objRSSChannel.Description%></font>
			</td>
		<tr>
		<tr><td> </td></tr>
		<%
		For Cont = 1 To objRSSChannel.Item.Count%>
		<tr>
			<td height="10" width="100%" colspan="2">
				<font face="verdana" size="2" color="#000000">
				<a href="<%=objRSSChannel.Item.Item(Cont).Link%>"><strong><%=objRSSChannel.Item.Item(Cont).Title%></strong></a>
				<br>
				<font size="1" color="#808080"><i><%=objRSSChannel.Item.Item(Cont).PubDate%></i></font>
				<br>
				<font size="1"><%=objRSSChannel.Item.Item(Cont).Description%></font>
				<br>
				<tt>Source: <%=objRSSChannel.Item.Item(Cont).Source.Url%></tt>
				</font>
				<p>
			</td>
		</tr>
		<%Next%>
	<%
	Set objRSSChannel = Nothing
	End If
	%>
	<tr><td height="100%"> </td></tr>
	</table>
	
</td></tr></table>
</center>

</body>
</html>
<%
Set objLeitorRSS = Nothing
%><!-- #include file="Classe_LeitorRSS.asp" -->
<%
Dim objLeitorRSS
Dim Mensagem
Dim Cont
Dim objRSSChannel
Set objLeitorRSS	= New LeitorRSS
Mensagem			= ""
If Not objLeitorRSS.ReadURL("http://g1.globo.com/Rss2/0,,AS0-5597,00.xml") Then
	Mensagem = objLeitorRSS.MensagemErro
Else
	Set objRSSChannel = New Channel
	Set objRSSChannel = objLeitorRSS.RSSChannel
End If
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Leitor RSS 2.0</title>
</head>
<body>
<center>
<table border="0" cellpadding="0" bgcolor="#000000" cellspacing="1" width="500" height="100%"><tr><td valign="top">

	<table border="0" cellpadding="0" bgcolor="#ffffff" cellspacing="0" width="500" height="100%">
	<%If Not Mensagem = "" Then%>
		<tr><td height="100%" valign="top"><font face="verdana" size="2" color="#ff8500"><%=Mensagem%></font></td></tr>
	<%Else%>
		<tr bgcolor="#000000">
			<td align="center" valign="middle" height="35" colspan="2">
				<strong><a href="<%=objRSSChannel.Link%>"><font face="verdana" size="2" color="#ff8500"><%=objRSSChannel.Title%></font></a></strong>
				<br>
				<font face="verdana" size="1" color="#ff8500"><%=objRSSChannel.PubDate%></font>
			</td>
		<tr>
		<tr bgcolor="#f0f0f0">
			<td valign="top" height="1%">
				<a href="<%=objRSSChannel.Image.Link%>"><img src="<%=objRSSChannel.Image.Url%>" alt="<%=objRSSChannel.Image.Title%>" border="0" align=baseline></a>
			</td>
			<td align="left" valign="top" height="10">
				<font face="verdana" size="2" color="#000000"><%=objRSSChannel.Description%></font>
			</td>
		<tr>
		<tr><td> </td></tr>
		<%
		For Cont = 1 To objRSSChannel.Item.Count%>
		<tr>
			<td height="10" width="100%" colspan="2">
				<font face="verdana" size="2" color="#000000">
				<a href="<%=objRSSChannel.Item.Item(Cont).Link%>"><strong><%=objRSSChannel.Item.Item(Cont).Title%></strong></a>
				<br>
				<font size="1" color="#808080"><i><%=objRSSChannel.Item.Item(Cont).PubDate%></i></font>
				<br>
				<font size="1"><%=objRSSChannel.Item.Item(Cont).Description%></font>
				<br>
				<tt>Source: <%=objRSSChannel.Item.Item(Cont).Source.Url%></tt>
				</font>
				<p>
			</td>
		</tr>
		<%Next%>
	<%
	Set objRSSChannel = Nothing
	End If
	%>
	<tr><td height="100%"> </td></tr>
	</table>
	
</td></tr></table>
</center>

</body>
</html>
<%
Set objLeitorRSS = Nothing
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.