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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implementing an XML Newsfeed?

Status
Not open for further replies.

Lurker03

Technical User
Oct 13, 2003
2
NZ
This is probably a very basic question but I'm afraid it's beyond my expertise!

I've just got approval to put a newsfeed on my site but they don't provide any assistance to add it. All they say is -

The newsfeed is updated three time a day at 6:55am (main from the days paper), 12:55 & 6:55pm (latest news headlines for the day). These files are provided on an "as is" basis. We cannot provide any additional assistance in getting these displayed on your site.

The feed format is in NITF 2.5 XML.

Each file represents a headline and link. These have a news category and subcategory detailed under the "tobject". The key field is "subect type" which you will find broken down into our main news categories being:

Ø News
Ø Business
Ø Sport
Ø Technology
Ø Entertainment
Ø Travel
Ø Money
Ø Property
Ø Motoring
Ø Employment

You will find that the "subject matter" does carry a sub category in some cases, eg:
Ø World (sub of News)
Ø Rugby, netball, league, cricket, etc (sub of sports)
Ø Economy, markets, agriculture, etc, (sub of Business)

They also provided a link to a folder of xml files.

Can anyone give me a clue as to how I add this to my site? Some example code would be gratefully appreciated!

Thanks.
 
Lurker03,

I'd like to do this too, have you manged to implement this? Also, where are you getting the feed from?

Thanks,

Mark
 
Very cool, but is there a way to include it from a site and not using external software or a plug in for IE? I want all visitors to my site to be able to see this without any action on their part.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
There are many different ways you can do this, the best/easiest way will depend on your knowledge base and how your current site is implemented. Are you using static HTML pages? JavaScript? ASP or PHP? etc.
 
My site uses ASP.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Just load in the XML as an XML object then you can use it however you want, probably with an XSL file.
 
Thanks I will give that a try.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
That would be great if you would not mind.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
My page is static HTML and I would really appreciate some example code. Details as in the original post.

Thanks.
 
ASP to load XML and transform to HTML with XSL:
Code:
<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load("[URL unfurl="true"]http://www.example.com/rss.xml")[/URL]

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("rss.xsl"))

'Transform file
Response.Write(xml.transformNode(xsl))
%>
With some sort of xsl:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="rss/channel">
    <html>
      <head>
        <title>
          <xsl:value-of select="title"/>
        </title>
      </head>
      <body>
        <dl>
          <xsl:for-each select="item">
            <dt>
              <a href="{link}">
                <xsl:value-of select="title"/>
              </a>
            </dt>
            <dd>
              <xsl:value-of select="description"/>
            </dd>
          </xsl:for-each>
        </dl>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
 
Or a JavaScript implementation:
Code:
<html>
<body>
<script type="text/javascript">
// Load XML 
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("[URL unfurl="true"]http://www.example.com/rss.xml")[/URL]

// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("rss.xsl")

// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>
 
JonyMC,

Thanks for posting. Ive added the ASP code to my site and created aXSL file using the second piece of code. For the ASP, I modified it to point to MSNBC using the link above. I placed the XSL in the same location as my ASP page. I don't get any errors, but I also don't get the newsfeed to display when I load the page.

Have I missed a step or done something wrong?

This is the path to the xml file I am using.

Thanks in advance.

Mark
 
I think its a security issue with your server not allowing XML to be loaded from an external server, as I have this problem too. If you save the XML locally and use this:
Code:
xml.load(Server.MapPath("rss.xml"))
It should work. I'll ask in the ASP forum how to solve this.
 
JonyMC, thanks again for posting. I gave the server.mapPath a try and that did not work either. I then tried deleting any other code from my page and still get the same results. Here is my most basic of pages (saved as an ASP page) please let me know if you see anthing wrong here. Thanks.

Code:
<%@ LANGUAGE="VBSCRIPT" %>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<table cellpadding="4" cellspacing="1" border="1" bgcolor="#ffffff" bordercolor="#99CCFF" width="100%" id="table2">
	<tr>
		<td bgcolor="#559BDA">
				<p align="center"><b>News Headlines</b>
		</td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF">&nbsp; 
		<%
		'Load XML
		set xml = Server.CreateObject("Microsoft.XMLDOM")
		xml.async = false
		' I have tried each of the following.  hte first pointing to the source XML and the second to a local copy.
		xml.load("[URL unfurl="true"]http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml")[/URL]
		'xml.load(Server.MapPath("msnbcnews.xml"))
		
		'Load XSL
		set xsl = Server.CreateObject("Microsoft.XMLDOM")
		xsl.async = false
		xsl.load(Server.MapPath("msnbc.xsl"))
		
		'Transform file
		Response.Write(xml.transformNode(xsl))
		%>
		</td>
	</tr>
</table>
</body>
</html>



I hope you find this post helpful.

Regards,

Mark
 
The XSL produces the whole HTML page. You just need the ASP code I posted on its own, not inside another HTML page else it won't work.
 
in the end I will need to figure out how to get this content in with the rest of my page, but I want to see it work first so I have done as suggested and removed all other content. That did get me further but I am getting an error regarding encoding.

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

System does not support the specified encoding. Error processing resource ' Line...

<?xml version="1.0" encoding="UTF-16"?>

What I don't get is where is it pulling the UTF-16. Each of my pages lists UTF-8 as copied from your example.


I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top