Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting an XML rss feed 2

Status
Not open for further replies.

ralphonzo

Programmer
Apr 9, 2003
228
GB
Does anyone have an idea how to interogate the 'description' tag of the rss feed from TechCrunch? I can't identify the image within the content in order to format it, and no matter what I try the text always pops up to its right at the bottom. I'm rubbish with XML!

There's a live model of what's happening at:
and here's my ASP/VBScript code:

Code:
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -->
<?xml version="1.0" encoding="utf-8"?>

<html>
<head>
<title>Clockwork Gallery</title>
<meta http-equiv="content-language" content="EN">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="100" border="0" cellpadding="0" cellspacing="10">
  <tr>
    <td><%
	dim xmlDom, nodeCol, oNode, oChildNode
	set xmlDom = Server.CreateObject("Microsoft.XMLDOM")
	'set xmlDom = Server.CreateObject("Msxml2.FreeThreadedDomDocument.4.0")  
	
	call xmlDom.setProperty("ServerHTTPRequest", true)
	xmlDom.async = false
	'call xmlDom.load("[URL unfurl="true"]http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml")[/URL]
	call xmlDom.load("[URL unfurl="true"]http://feeds.feedburner.com/Techcrunch")[/URL]
	
	
	if not xmlDom.documentElement is nothing then
	  set nodeCol = xmlDom.documentElement.selectNodes("channel/item")
	  for each oNode in nodeCol
		Response.Write("<p>"& vbCrLf)
		'set oChildNode=oNode.selectSingleNode("*[local-name()='content']/@url")
		'if not oChildNode is nothing then
			'Response.Write "<img src=""" & oChildNode.NodeValue & """ alt=""" & ochildnode.NodeValue & """ />XYZ<br />" & vbcrlf
		'end if
		set oChildNode = oNode.selectSingleNode("title")
		if not oChildNode is nothing then
		  Response.Write("  <h3>" & oChildNode.text & "</h3>" & vbCrLf)
		end if
		'set oChildNode = oNode.selectSingleNode("pubDate")
		'if not oChildNode is nothing then
		 ' Response.Write("  &raquo; " & oChildNode.text & "<br />" & vbCrLf)
		'end if
		set oChildNode = oNode.selectSingleNode("description")
		if not oChildNode is nothing then
		  Response.Write("  " & oChildNode.text & "<br />" & vbCrLf)
		end if
		set oChildNode = oNode.selectSingleNode("link")
		if not oChildNode is nothing then
		  Response.Write("  <br />" & vbCrLf)
		  Response.Write("  <a href=""" & oChildNode.text & """ target=""_blank"">")
		  Response.Write("    more..." & vbCrLf)
		  Response.Write("  </a>" & vbCrLf)
		end if
		Response.Write("</p>" & vbCrLf)
	  next
	else
	  Response.Write("<p>" & vbCrLf)
	  Response.Write("  Sorry, no news today!" & vbCrLf)
	  Response.Write("</p>" & vbCrLf)
	end if %></td>
  </tr>
</table>
</body>
</html>
 
set oChildNode = oNode.selectSingleNode("description")
oChildNode.text

does the above not work then?
 
Yes it renders, but I can't change how it renders (see how it throws it on the page here: I'm afraid my XML skills aren't up to much. It's very rare I need XML, as I use databases. Is it possible to display the contents of 'description' so that it's possible to see how the individual component elements can be manipulated?
 
looks fine to me.
seeing as you get the description nodes text and you can display it on the page? then i feel the issue is not strictly xml, you should like you just dont like the format of how it appears, this, i would suggest is due to the HTML you are creating. perhaps some revision in HTML would help you
 
i might be talking pony but with xml i am sure you are supposed to be able to 'transform' it. you have to author a transform file. i guess the difference is that you wont have to maintain / author any code to search though the xml and then render it. i would hope the transform would be more efficient as well. i would recommend you have a look at the xml forum
 
>i would recommend you have a look at the xml forum
No, I had tried best to help. The op seems to be just disgusted at the outcome rather than trying to explain what they need or perhaps they don't know what they need except let the need be discovered along the process.
 
sorry tsuji ;-), i knew by saying 'try the xml forum' it was really 'try tsuji for help'
personally i think the op's page looks fine, i can read it, for me websites stand and fall by their content not their look, im not the younger generation though.
have a good day
 
>have a good day
You too, mrmovie. And have a great Year of Tiger, like we say in this part of the globe at this time.
 
OK, that's what I need to be able to do, to transform the XML into HTML. I've no problem with HTML, so how can I edit a closed tag, such as 'description' so that I can view it's internal elements. These are not evident in the XML source code.
 
[0] >so how can I edit a closed tag, such as 'description' so that I can view it's internal elements.
You have to be more precise. "View" in what sense?

[1] I may be seemed to be very critical to all these, but it is that important to be precise. I can guess what you mean and why you are lost. You want to view the content of description element as if they are dom elements and use the xml parser to parse them.

[2] The text content of the description is deliberately passed like that as CDATA for other considerations. It does not stand ready to be parsed as xml document just by a click of fingers, nor for people who shout they have no time to learn and just want to be able to be skilled at that.

[3] Now, you settle with the description, I can try to show you how by some specific results returned. You have to learn from the script below and to extend it to your other needs. For sure, do not expect hand-held like you seem to believe the rights to have.
[tt]
'I suppose this line is done properly - ok?
set oChildNode = oNode.selectSingleNode("description")
sxml=oChildNode.text
sxml=replace(sxml,"&","&[highlight]_[/highlight]amp;") '[red]take out the underscore: the stupid tgml processing decision of this site works against users[/red]

'since you seem to stick to microsoft.xmldom, I told you once what should use, I won't tell twice.
set oparser=server.createobject("msxml2.freethreadeddomdocument.4.0")
bret=oparser.loadxml("<x>" & sxml & "</x>")
if not bret then
'description text won't be ready to be treated as xml fragment; I do nothing about it.
else
set cnodes=oparser.SelectNodes("//img/@src")
for j=0 to cnodes.length-1
response.write "<div>img src's url: " & cnodes(j).NodeValue & "</div>" 'I do no formatting decision at your place, do whatever you want with .NodeValue now available
next
set cnodes=nothing
end if
set oparser=nothing
[/tt]
 
OK, that all works dandy, except there's nothing being returned in 'sxml' or 'bret', therefore 'cnodes(j).NodeValue' is not even being set.
 
>[self]>'I suppose this line is done properly - ok?
>[self]>set oChildNode = oNode.selectSingleNode("description")
That is your line. I suppose you've done it correctly. Is it clear? You have response.write of its .text. What do you get?
 
This is the script:

Code:
dim xmlDom, nodeCol, oNode, oChildNode
set xmlDom = Server.CreateObject("Msxml2.FreeThreadedDomDocument.4.0")  
	
call xmlDom.setProperty("ServerHTTPRequest", true)
xmlDom.async = false
call xmlDom.load("[URL unfurl="true"]http://feeds.feedburner.com/Techcrunch")[/URL]
	
if not xmlDom.documentElement is nothing then
   set nodeCol = xmlDom.documentElement.selectNodes("channel/item")
   for each oNode in nodeCol
	Response.Write("<p>"& vbCrLf)
		
	set oChildNode = oNode.selectSingleNode("title")
	if not oChildNode is nothing then
	   Response.Write("  <h3>" & oChildNode.text & "</h3>" & vbCrLf)
	end if
		
	set oChildNode = oNode.selectSingleNode("description")
	sxml=oChildNode.text
	sxml=replace(sxml,"&","&_amp;")    
		
	bret=xmlDom.loadxml("<x>" & sxml & "</x>")
	if not bret then
	   response.write "<div>There's nothing here</div>"
	else
	   set cnodes=xmlDom.SelectNodes("//img/@src")
	   response.write "<div>cnodes.length: " & cnodes.length & "</div>"
	   for j=0 to cnodes.length-1
		response.write "<div>img src's url: " & cnodes(j).NodeValue & "</div>"    
	   next
	   set cnodes=nothing
	end if
		
	set oChildNode = oNode.selectSingleNode("link")
	   if not oChildNode is nothing then
		  Response.Write("  <br />" & vbCrLf)
		  Response.Write("  <a href=""" & oChildNode.text & """ target=""_blank"">")
		  Response.Write("    more..." & vbCrLf)
		  Response.Write("  </a>" & vbCrLf)
	   end if
	   Response.Write("</p>" & vbCrLf)
   next
else
   Response.Write("<p>" & vbCrLf)
   Response.Write("  Sorry, no news today!" & vbCrLf)
   Response.Write("</p>" & vbCrLf)
end if

All that is displayed is the Title, the string 'There's nothing here', and the 'more...' link.
 
Can you answer directly, before my post, you seem to say in reponse to mrmovie's question:
>[mrmovie:]>does the above not work then?
>Yes it renders, but I can't change how it renders...
My question was what is the outcome of the response.write (ochildNode.text)??? Just to make sure you meant what you said? Or you mean oChildNode shows nothing in the response.write? I can't ask many more times the same question.
 
The result of 'response.write ochildNode.text' is an image (url found via right click->properties: followed by the text content (beginning with one line to the right and at the foot of the preceding image).

sxml displays the same info, but when it gets to 'bret' 'false' results, hence the 'There's nothing here' string displaying.

Code:
set oChildNode = oNode.selectSingleNode("description")
if not oChildNode is nothing then
	Response.Write("  <h3>" & oChildNode.text & "</h3>" & vbCrLf)
end if
sxml=oChildNode.text
sxml=replace(sxml,"&","&_amp;")    
if not oChildNode is nothing then
	Response.Write("  <h6>" & sxml & "</h6>" & vbCrLf)
end if		
bret=xmlDom.loadxml("<x>" & sxml & "</x>")
if not oChildNode is nothing then
	Response.Write("  <h6>" & bret & "</h6>" & vbCrLf)
end if	
if not bret then
	response.write "<div>There's nothing here</div>"
else
	set cnodes=xmlDom.SelectNodes("//img/@src")
	response.write "<div>cnodes.length: " & cnodes.length & "</div>"
	for j=0 to cnodes.length-1
		response.write "<div>img src's url: " & cnodes(j).NodeValue & "</div>"    
	next
	set cnodes=nothing
end if

What is 'bret' there to achieve?
 
Have you taken out the underscore I'd highlighted up there?
 
Ah, I misunderstood that bit. And the results are...editable, thank you. What a ridiculous underscore that is!! Big star coming your way Tsuji. Thank you again, now I can get on :eek:)
 
There's another problem with this. 'response.write "<img src=" & cnodes(1).NodeValue & ">"' always displays the 'http\\' string and not what is contains. Is there a way of displaying its contents?
 
Sorry, I copied the wrong line there. It's 'response.write cnodes(1).NodeValue' that's the problem and contains the non-image text string element that I can't get to render.
 
All the rendering happens on the client-side. As far as the server is concerned, it is all strings, or in most cases...

If you want to see images, you have to make it serving the right html tags. Something like this.
[tt]
if not bret then
response.write "<div>There's nothing here</div>"
else
set cnodes=xmlDom.SelectNodes("//img/@src")
response.write "<div>cnodes.length: " & cnodes.length & "</div>"
for j=0 to cnodes.length-1
response.write "<div><img src='" & cnodes(j).NodeValue & "' alt='image (0,'" & j & ")' /></div>"
next
set cnodes=nothing
end if
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top