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

Struggling to return xml attribute value from external url

Status
Not open for further replies.

gibblin

Technical User
Oct 9, 2003
27
GB
Hi,

I have the following code from w3schools.
-----------------------------------------------

<html>
<body>
<script type="text/javascript">

function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

///external feed
xml=loadXMLDoc("hxxp://xml.stanjames.com/football-thechampionship.XML");

///my own feed
//xml=loadXMLDoc("feed.xml");

path="/category/event[@name='Sheff Wed v Doncaster']/bettype[@name='Match Betting 90 Minutes']/bet[@had-value='DRAW']/@price";

// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);

for (i=0;i<nodes.length;i++)
{
document.write(nodes.childNodes[0].nodeValue);
document.write("<br />");
}
}

// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE,null);
var result=nodes.iterateNext();

while (result)
{
document.write(result.childNodes[0].nodeValue);
document.write("<br />");
result=nodes.iterateNext();
}
}
</script>
</body>
</html>


Now, if i have my own xml file, as follows, it works fine and returns "11/5".

<category>
<event name="Sheff Wed v Doncaster">
<bettype name="Match Betting 90 Minutes">
<bet had-value="DRAW" name="Draw" price="11/5" />
<bet had-value="HOME" name="Barnsley" price="7/4" />
<bet had-value="AWAY" name="Sheff Utd" price="11/8" />
</bettype>
</event>
</category>


However, if i try to use the external url it doesn't work. The external xml is basically set up as above but with more information in it, but it just won't retrieve it and i don't understand why. There's no errors or alerts.

Would anyone have any idea why this would be the case?

please note, i've changed the http to hxxp so it isn't linked within this post.
 
[1] In moz-based browser, add this block before the load.
[tt]
if (document.implementation && document.implementation.createDocument) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
}
[/tt]
[2] In that happens on ie, add the site to your list of trusted site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top