View Full Version : java script to load xml from url

12-07-2009, 12:05 PM
I have to load an xml from a url and process the request.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<body onload="readXmlFile()">
If all goes well you should see an alert box display the message 'testing 123'
<p>Press the 'go' button to read the xml file '<a href="test123">test123</a>'
from the web server.
<input type="button" onclick="readXmlFile()" value="go"/>

<script type="text/javascript">
XML.load = function(url) {
var xmldoc = XML.newDocument();
xmldoc.async = false;
return xmldoc;

XML.newDocument = function(rootTagName, namespaceURL) {
if (!rootTagName) rootTagName = "";
if (!namespaceURL) namespaceURL = "";

if (document.implementation && document.implementation.createDocument) {
// This is the W3C standard way to do it
return document.implementation.createDocument(namespaceURL,
rootTagName, null);
else { // This is the IE way to do it
// Create an empty document as an ActiveX object
// If there is no root element, this is all we have to do
var doc = new ActiveXObject("MSXML2.DOMDocument");

// If there is a root tag, initialize the document
if (rootTagName) {
// Look for a namespace prefix
var prefix = "";
var tagname = rootTagName;
var p = rootTagName.indexOf(':');
if (p != -1) {
prefix = rootTagName.substring(0, p);
tagname = rootTagName.substring(p+1);

// If we have a namespace, we must have a namespace prefix
// If we don't have a namespace, we discard any prefix
if (namespaceURL) {
if (!prefix) prefix = "a0"; // What Firefox uses
else prefix = "";

// Create the root element (with optional namespace) as a
// string of text
var text = "<" + (prefix?(prefix+":"):"") + tagname +
?(" xmlns:" + prefix + '="' + namespaceURL +'"')
:"") +
// And parse that text into the empty document
return doc;

function readXmlFile() {
url = 'http://open.api.ebay.com/shopping?callname=FindItems&responseencoding=XML&appid=AneeshVK-1af9-4429-99ab-99fa586437ca&siteid=3&version=515&SellerID=timbarson1';
doc = XML.load(url);

but i am getting error while the url is called for loading.

the error is

Error: uncaught exception: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://localhost/bulbtemplate/abcd.html Line: 26"]

i am running it from xampp. i am badly stuck here and would like to have any advice/help in this. I have to load this xml and process it to take the details to display in the page