473,379 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

RSS Newsfeed

Hi. I wrote a simple asp script to read various rss newsfeeds. I got
one newsfeed, however, that comes back with a runtime error ['null' is
null or not an object]. Here's the code, distilled to the point of
error:

//
function xml_load(src) {
try {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
}
catch (e) {
alert(e)
return null
}
return xmlDoc
}
//
function xml_start() {
var xmlDoc = xml_load("http://stardate.org/feeds/rss.xml")
if (typeof(xmlDoc) != "object") return ''
var root = xmlDoc.documentElement
if (typeof(root) != "object") return ''
if (typeof(root.childNodes) != "object") return '' // bombs here
}
I'm at a loss. How can you have a xmlDoc object having no childNodes?
Is there something wrong with the file http://stardate.org/feeds/rss.xml
? No encode statement? Any advice would be appreciated...Dennis
Jul 27 '05 #1
12 1842
VK
Dennis Allen wrote:
Hi. I wrote a simple asp script to read various rss newsfeeds. I got
one newsfeed, however, that comes back with a runtime error ['null' is
null or not an object]. Here's the code, distilled to the point of
error:

//
function xml_load(src) {
try {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
}
catch (e) {
alert(e)
return null
}
return xmlDoc
}
//
function xml_start() {
var xmlDoc = xml_load("http://stardate.org/feeds/rss.xml")
if (typeof(xmlDoc) != "object") return ''
var root = xmlDoc.documentElement
if (typeof(root) != "object") return ''
if (typeof(root.childNodes) != "object") return '' // bombs here
}
I'm at a loss. How can you have a xmlDoc object having no childNodes?
Is there something wrong with the file http://stardate.org/feeds/rss.xml
? No encode statement? Any advice would be appreciated...Dennis

As the first guess the stargate.org's admin did not set MIME for XML
('text/xml'). As the result responseXML cannot be used by XMLDOM (but
naturally XMLDOM as object still exists).
As XML/XLT serving remains (still!) a rather new bist, it is more
secure do not count on server admins but use MSXML parser for
responseText, here you will not wail.
The all times winner link:
<http://support.microsoft.com/Default.aspx?id=893659>

Jul 27 '05 #2


Dennis Allen wrote:
Hi. I wrote a simple asp script to read various rss newsfeeds. I got
one newsfeed, however, that comes back with a runtime error ['null' is
null or not an object]. Here's the code, distilled to the point of
error:

//
function xml_load(src) {
try {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
These (e.g. Microsoft.XMLHTTP) are program ids that make sense on the
client where you don't know which MSXML version is installed but in an
ASP script on the server you should find out which MSXML version is
installed and use one. In particular there is a special server side
version of XMLHTTP, e.g. for MSXML 4 Msxml2.ServerXMLHTTP.4.0.
xmlhttp.open("GET",src,false)
xmlhttp.send()
To find out what is happening respectively what is going wrong you can
examine
xmlhttp.status
xmlhttp.statusText
xmlhttp.getAllResponseHeaders()
xmlDoc = xmlhttp.responseXML
and then here
xmlDoc.parseError.errorCode
xmlDoc.parseError.reason
}
catch (e) {
alert(e)


alert in an ASP script? That is not going to work.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 27 '05 #3
I saw that site. Very confusing. Is it possible to test
xmlhttp.responseXML? If xmlDoc doesn't have the proper properties,
could we create code that would populate xmlDoc?
"VK" <sc**********@yahoo.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Dennis Allen wrote:
Hi. I wrote a simple asp script to read various rss newsfeeds. I
got
one newsfeed, however, that comes back with a runtime error ['null'
is
null or not an object]. Here's the code, distilled to the point of
error:

//
function xml_load(src) {
try {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
}
catch (e) {
alert(e)
return null
}
return xmlDoc
}
//
function xml_start() {
var xmlDoc = xml_load("http://stardate.org/feeds/rss.xml")
if (typeof(xmlDoc) != "object") return ''
var root = xmlDoc.documentElement
if (typeof(root) != "object") return ''
if (typeof(root.childNodes) != "object") return '' // bombs here
}
I'm at a loss. How can you have a xmlDoc object having no
childNodes?
Is there something wrong with the file
http://stardate.org/feeds/rss.xml
? No encode statement? Any advice would be appreciated...Dennis

As the first guess the stargate.org's admin did not set MIME for XML
('text/xml'). As the result responseXML cannot be used by XMLDOM (but
naturally XMLDOM as object still exists).
As XML/XLT serving remains (still!) a rather new bist, it is more
secure do not count on server admins but use MSXML parser for
responseText, here you will not wail.
The all times winner link:
<http://support.microsoft.com/Default.aspx?id=893659>

Jul 27 '05 #4
VK
Dennis Allen wrote:
I saw that site. Very confusing. Is it possible to test
xmlhttp.responseXML?


If you want to be academic, *after* readyState==4 you always should:

if (myRequest.getResponseHeader("Content-Type") != "text/xml") {
// I'm in troubles
}

If you want to be a simple guy, *after* readyState==4 you always
should:

if (!myRequest.responseXML) {
// Damn that admin!
}

Even if MIME is not set to "text/xml", the XML content is here
(presuming you have loaded a valid XML file). It's just not considered
to be an XML object. For browser it's a set of strings, nothing more.
You need to *parse* it into XML. It is very easy on IE, rather tricky
on FF and rather impossible on other wannabes.

Before going into details: check myRequest.getResponseHeader on IE from
the site of the question. If it appears that the admin indeed gets his
doughnuts for nothing, let's talk further.

Jul 27 '05 #5
I tweeked xml_load() :

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
// var szResponse = xmlhttp.responseText
// xmlDoc.loadXML(szResponse)
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}

Something interesting. On the stardate.org xml file, if I change the
code to:

// xmlDoc = xmlhttp.responseXML
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)

....it works. But using this code breaks other newsfeeds (DTD not
found). Is there a way to test for error and use one way, then the
other?
Jul 29 '05 #6

"VK" <sc**********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Dennis Allen wrote:
I saw that site. Very confusing. Is it possible to test
xmlhttp.responseXML?


If you want to be academic, *after* readyState==4 you always should:

if (myRequest.getResponseHeader("Content-Type") != "text/xml") {
// I'm in troubles
}

If you want to be a simple guy, *after* readyState==4 you always
should:

if (!myRequest.responseXML) {
// Damn that admin!
}

Even if MIME is not set to "text/xml", the XML content is here
(presuming you have loaded a valid XML file). It's just not considered
to be an XML object. For browser it's a set of strings, nothing more.
You need to *parse* it into XML. It is very easy on IE, rather tricky
on FF and rather impossible on other wannabes.

Before going into details: check myRequest.getResponseHeader on IE
from
the site of the question. If it appears that the admin indeed gets his
doughnuts for nothing, let's talk further.


I tweeked xml_load() :

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
// var szResponse = xmlhttp.responseText
// xmlDoc.loadXML(szResponse)
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}

I hope this is the way it should be written. Something interesting. On
the stardate.org xml file, if I change the code to:

// xmlDoc = xmlhttp.responseXML
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)

....it works. But using this code breaks other newsfeeds (DTD not
found). Is there a way to test for error and use one way, then the
other?
Jul 29 '05 #7
Hi again. After much trial and error, I found a routine that makes all
the newsfeeds happy:

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
if (typeof(xmlDoc) != "object" ||
xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)
}
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}

Jul 29 '05 #8
Hi. After much trial and error, I found a routine that makes all the
newsfeeds happy:

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
if (typeof(xmlDoc) != "object" ||
xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)
}
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}
Jul 29 '05 #9
VK

Dennis Allen wrote:
Hi. After much trial and error, I found a routine that makes all the
newsfeeds happy:

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
if (typeof(xmlDoc) != "object" ||
xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)
}
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}
Dennis Allen wrote: Hi. After much trial and error, I found a routine that makes all the
newsfeeds happy:

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
if (typeof(xmlDoc) != "object" ||
xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)
}
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}
Dennis Allen wrote: Hi. After much trial and error, I found a routine that makes all the
newsfeeds happy:

//
function xml_load(src) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
xmlhttp.open("GET",src,false)
xmlhttp.send()
xmlDoc = xmlhttp.responseXML
if (typeof(xmlDoc) != "object" ||
xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {
var szResponse = xmlhttp.responseText
xmlDoc.loadXML(szResponse)
}
if (typeof(xmlDoc) != "object") return 'no object defined'
if (xmlDoc.parseError.errorCode != 0) {
var x = ''
x += 'Error in File: ' + xmlDoc.parseError.url + '<br>'
x += 'Error on Line: ' + xmlDoc.parseError.line + '<br>'
x += 'Error Code : ' + xmlDoc.parseError.errorCode + '<br>'
x += 'Error Reason : ' + xmlDoc.parseError.reason
return x
}
return xmlDoc
}

Could be simplier, but it does the trick.

If you add in

if xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {}

block an option for DOMParser:

....
var parser = new DOMParser();
var doc =
parser.parseFromString(xmlhttp.responseText,"appli cation/xml");
....

it will also fix the situation for Firefox and Opera 8
But actually what *really* should be done:
Go to <http://www.vwh.net/services/contactus_form.cfm> (by tracert this
is the host provider of stardate.org), choose "Webmaster" as addressee,
and write him to bring his MIME's headers in the decent state if he
wants to get one more free breakfast doughtnut in his sorry life.

Jul 29 '05 #10

"VK" <sc**********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...


Could be simplier, but it does the trick.

If you add in

if xmlhttp.GetResponseHeader("Content-Type") != "text/xml") {}

block an option for DOMParser:

...
var parser = new DOMParser();
var doc =
parser.parseFromString(xmlhttp.responseText,"appli cation/xml");
...

it will also fix the situation for Firefox and Opera 8


A block of DOMParser code for Firefox and Opera? How?
Jul 29 '05 #11
VK
Dennis Allen wrote:
A block of DOMParser code for Firefox and Opera? How?


So far your code is too Microsoft-oriented. Take something more
universal for the starting point. Maybe the discovery prototype itself
(that started all this biz)? That would be the best:
<http://jibbering.com/2002/4/httprequest.html>

<pseudo-code>
if IE
create XMLHttpRequest using
if IIS server : proper version of MSXML
if client : Microsoft.XMLHTTP
create MicrosoftXMLParser using
if IIS server : proper version of MSXML
if client : Microsoft.XMLDOM

else if XMLHttpRequest supported {
create XMLHttpRequest using
new XMLHttpRequest()
if window.DOMParser available
create MozillaXMLParser using
parser = new DOMParser();

else
XMLHTTP FUBAR

getXMLData

if Content-Type is not "text/xml"
if MicrosoftXMLParser
MicrosoftXMLParser.loadXML(xmlhttp.responseText)
else if MozillaXMLParser

MozillaXMLParser.parseFromString(xmlhttp*.response Text,"application/xml*");

// BTW: why "application/xml*" ???
// But this is what Mozilla docs imply
else
XMLHTTP FUBAR
else
use xmlhttp*.responseXML
</pseudo-code>

Jul 29 '05 #12
Thanks for the reply. Tested the asp script with IE6, Foxfire, NS7,
Opera, even NS4. No problem with any of the newsfeeds. When I get
time, I'll look into it some more.

"VK" <sc**********@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Dennis Allen wrote:
A block of DOMParser code for Firefox and Opera? How?


So far your code is too Microsoft-oriented. Take something more
universal for the starting point. Maybe the discovery prototype itself
(that started all this biz)? That would be the best:
<http://jibbering.com/2002/4/httprequest.html>

<pseudo-code>
if IE
create XMLHttpRequest using
if IIS server : proper version of MSXML
if client : Microsoft.XMLHTTP
create MicrosoftXMLParser using
if IIS server : proper version of MSXML
if client : Microsoft.XMLDOM

else if XMLHttpRequest supported {
create XMLHttpRequest using
new XMLHttpRequest()
if window.DOMParser available
create MozillaXMLParser using
parser = new DOMParser();

else
XMLHTTP FUBAR

getXMLData

if Content-Type is not "text/xml"
if MicrosoftXMLParser
MicrosoftXMLParser.loadXML(xmlhttp.responseText)
else if MozillaXMLParser

MozillaXMLParser.parseFromString(xmlhttp*.response Text,"application/xml*");

// BTW: why "application/xml*" ???
// But this is what Mozilla docs imply
else
XMLHTTP FUBAR
else
use xmlhttp*.responseXML
</pseudo-code>
Jul 29 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phong Ho | last post by:
Hi everyone, I use the MagpieRSS parser to read RSS newsfeeds. I am able to get the title, url and description. However, I do not able to get the time or date the newsfeed was last published....
0
by: Trevor Andrews | last post by:
The NewsTrove.com news search engine has a new feature that allows you to create your own RSS news feed with any combination of keywords on any topic. The URL to the 'build your own RSS' is:...
0
by: Specter | last post by:
Code: ____________________________________________________ <?PHP header("Content-type: text/xml"); echo"<?xml version=\"1.0\" encoding=\"windows-1252\" ?> <rss version=\"0.91\" > <channel>...
0
by: Peter Callen | last post by:
I have set up a medical website and have a side bar with other links and information. For 2-3 years I had used a newsfeed called Newsclicker. As best I can tell, they no longer function as the...
0
by: | last post by:
I am trying to create an ASP.NET application that consumes an RSS Newsfeed from Yahoo News (http://rss.news.yahoo.com/rss/topstories). I keep getting the following error message, even though my...
7
by: Don | last post by:
Via JavaScript within the client page containing the checkbox, I'm trying to capture the value of a checkbox to make a cookie out of it. But, all I get is the defined "ON" value, even when it is...
10
by: Tim B. | last post by:
Hello, I am looking for the proper way to shut down db2 completely so that I can do a cold back up on all the databases. Thanks! ----== Posted via Newsfeed.Com -...
10
by: Default User | last post by:
Sorry about this. Our newsfeed here has periodic problems where posts to our main feed don't make it outside. Unfortunately, the alt groups are on a different feed, so posts to alt.test don't...
1
by: =?Utf-8?B?U3RldmVI?= | last post by:
Hello I have a ASP script which allows me to see Internet-related news items from the BBC in a normal browser. I would like to be able to view this feed in a dynamic text box in Flash MX 2004,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.