Does anyone know how to call the data based on an element attribute. ie, i want to call whether ONE product is in stock, based on its 'NAME'.
Ie; HTML would display "In Stock." on an HTML page that calls the 'STOCK' value for the 'PRODUCT' element with 'NAME' attribute 'product 1' but a different HTML page would display "out of stock." as it would call 'STOCK' value from 'PRODUCT' element with 'NAME' attribute 'product 2'.
I've been trying to figure this out forever if anyone can help id be really greatful, i guess its probably quite easy?
I'm not sure if that would work, but a quick test suggests it would... Out of curiosity, why not store how many are in stock instead? That way, you could determine if you were out of stock based upon whether the number stockpiled is 0. Then you could store it as an attribute, and the structure wouldn't be so weird.
Unfortunately its not my xml feed, its from my supplier and its hosted on their servers. I tried what you said but no joy perhaps its because the xml is not hosted on my server, i know browsers have some access rules for security... is there a workaround?
I have been trying:
Code:
<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);
}
xml=loadXMLDoc("http://www.supplier.com/catalog/xml-feed/stock.xml");
path="/STOREITEMS/PRODUCT[@NAME=$product 1]/STOCK[contains(., "In")]/.."
// code for IE
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].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>
JavaScript's too iffy anyway. Better to find a nice server side solution. What server side scripting do you have available?
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Several, but the good folks on the PHP forum will be better able to help you. But they will need to know what version of PHP you have and what modules are installed. (There is a big difference between PHP 4 & 5 in the XML department.)
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Bookmarks