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

xmlHTTP Error

Status
Not open for further replies.

tayorolls

MIS
May 8, 2007
42
US
Hi,

I am getting an error while taking feeds for our organization. Apparently that URL was down for a while.


Code:
<!-- ****************** Begin News Modules ****************** -->
	<style>
		body {font-family: Verdana, Arial, Helvetica, sans-serif;}
		div.news-header-employee {background-color:#9090f9; font-size: 75%; font-weight: bold; color: #ffffff; padding:2px; text-align:center;}
		div.news-header-industry {background-color:#9090f9; font-size: 75%; font-weight: bold; color: #ffffff; padding:2px; text-align:center;}
	</style>

	<div style="margin:0px 5px 0px 5px">
		<div class="news-header-employee">Company Employee News</div>
		<!--#include virtual="/inc/RSSParser.inc"-->
		<!--#include virtual="/inc/NewsDB_Company.inc"-->
		 Code:  <!--#include virtual="/inc/NewsRSS_Company.inc"--> 		<br />
	

		<div class="news-header-industry">Industry News</div>
		<!--#include virtual="/inc/NewsRSS_Yahoo.inc"-->
		<br />
	</div>
	
<!-- ****************** End News Modules ****************** -->

In the bold line above, in that file:


Code:
<script language="JScript" runat="Server">

	// Create XML Object
	var rssURL = "[URL unfurl="true"]http://my.company.com/intranet/feed.jsp?feed=rss/broadcast&pt=intranet/cas&c=e"[/URL]
	var newsCompany = getXMLObject(rssURL);
	
</script>

In case the URL is down, how do I display just a simple text saying that the "No News" instead of causing the entire intranet to crash.

Error I was getting is:

Code:
Error Type:
msxml3.dll (0x800C0005)
The system cannot locate the resource specified. 
/inc/RSSParser.inc, line 22

Line 22 in RSSParser.inc is: (In bold)


Code:
<script language="JScript" runat="Server">

/*********************************************
CORE XMLHTTPREQUEST OBJECT
Grabs an XML document, and converts it to a XMLDOM 
object so that it can be parsed with DOM methods.
*********************************************/
function getXMLObject(url) {
	var xmlhttp, xmldoc;

	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	xmlhttp.open("GET", url, false);
             xmlhttp.send(null);	//return xmlhttp.ResponseText;

	xmldoc=Server.CreateObject("Microsoft.XMLDOM");
	xmldoc.async=false;
	xmldoc.loadXML(xmlhttp.ResponseText);

	if (xmldoc.parseError.errorCode != 0) {
		Response.Write("<HR>");
		Response.Write("XML Parser Error on Line:");
		Response.Write(xmldoc.parseError.line);
		Response.Write(", Character:");
		Response.Write(xmldoc.parseError.linePos);
		Response.Write("<BR>");
		Response.Write(xmldoc.parseError.srcText);
		Response.Write("<HR>");
	}

	return xmldoc;
}

Thanks.
 
This will make provision on the major sources of error.
[tt]
function getXMLObject(url) {
var xmlhttp, xmldoc;

try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
[blue]Response.write "Server does not support xmlhttp.<br />"
return new Object(); //caller expecting object return[/blue]
[red]//[/red]xmlhttp = false;
}
}
xmlhttp.open("GET", url, false);
[blue]try {[/blue]
xmlhttp.send(null); //return xmlhttp.ResponseText;
[blue]} catch (e) {
Response.write ("Server cannot locate the resource host.<br />");
Response.write ("error : " + e.number + "<br />");
Response.write ("description : " + e.description + "<br />");
return new Object();
}[/blue]

[blue]if (xmlhttp.status == 200 ||xmlhttp.status == 0) { //in case local to server as well[/blue]

[red]//[/red]xmldoc=Server.CreateObject("Microsoft.XMLDOM");
[blue]xmldoc=new ActiveXObject("Microsoft.XMLDOM");[/blue]
xmldoc.async=false;
xmldoc.loadXML(xmlhttp.ResponseText);

if (xmldoc.parseError.errorCode != 0) {
Response.Write("<HR>");
Response.Write("XML Parser Error on Line:");
Response.Write(xmldoc.parseError.line);
Response.Write(", Character:");
Response.Write(xmldoc.parseError.linePos);
Response.Write("<BR>");
Response.Write(xmldoc.parseError.srcText);
Response.Write("<HR>");
[blue]return new Object();[/blue]
}

[blue]} else {
Response.write ("Server cannot locate the resource.<br />");
Response.write ("xmlhttp status : " + xmlhttp.status + "<br />");
return new Object();
}[/blue]

return xmldoc; [green]//the only place to return without major error[/green]
}
[/tt]
When you capture the return object, newCompany.xml being empty will be symptomatic to error happened one way or another.
 
Amendment
The corresponding line should be read like this (forgotten parentheses for js).
[tt]Response.write [red]([/red]"Server does not support xmlhttp.<br />"[red]);[/red][/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top