Quote
Expected token ')' found ':'.
dataroot/OrderQuery[not(CustomerName=preceding-sibling-->:<--:OrderQuery/CustomerName)]/CustomerName
dataroot/OrderQuery[not(CustomerName=preceding-sibling-->:<--:OrderQuery/CustomerName)]/CustomerName
I am guess that it has something to do with with the ActiveXObject but I'm not sure. I am trying to retrieve a list of unique customer names from the xml document.
Any ideas?
function loadXML(file) {
"use strict";
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET", file, false);
xhttp.send("");
return xhttp.responseXML;
}
function getCustomers(xml)
{
var path = "dataroot/OrderQuery[not(CustomerName=preceding-sibling::OrderQuery/CustomerName)]/CustomerName";
var customers = new Array();
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
for (i=0;i<nodes.length;i++)
{
customers[i] = nodes[i].childNodes[0].nodeValue;
}
}
// 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();
var i = 0;
while (result)
{
customers[i] = result.childNodes[0].nodeValue;
i++;
result=nodes.iterateNext();
}
}
return customers;
}
function getCustomerOrders(xml, customer)
{
var path = "dataroot/OrderQuery[CustomerName='" + customer + "']";
var orders = new Array();
if (window.ActiveXObject)
{
var nodes=xml.selectNodes(path);
var children, i = 0, k = 0, currentOrder = new Array();
for (i=0;i<nodes.length;i++)
{
children = nodes[i].childNodes;
for (j = 0; j < children.length; j++)
{
if (children[j].nodeType == 1)
{
currentOrder[j] = children[j].childNodes[0].nodeValue;
}
}
}
}
// 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();
var i = 0, k = 0, orders = new Array();
var children;
while (result)
{
children = result.childNodes;
i = 0;
var currentOrder = new Array();
for (j = 0; j < children.length; j++)
{
if (children[j].nodeType == 1)
{
currentOrder[i] = children[j].firstChild.nodeValue;
i++;
}
}
orders[k] = currentOrder;
k++;
result=nodes.iterateNext();
}
}
return orders;
}
function init() {
"use strict";
var file = "xml/OrdersByCustomer.xml";
//var path = "dataroot/OrderQuery[CustomerName='Abel & Young' and OrderID='1']/ProductName";
var xml = loadXML(file);
var customerList, i = 0, j = 0, output, orders = new Array();
customerList = getCustomers(xml);
customerList.sort();
output = "<table><tr><td>Customer Name</td><td>Order ID</td><td>OrderDate</td><td>Product Name</td><td>Quantity</td></tr>";
for (i = 0; i < customerList.length; i++)
{
output += "<tr><td>" + customerList[i] + "</td><td></td><td></td><td></td><td></td></tr>"; // create first row
orders = getCustomerOrders(xml, customerList[i]);
for (j = 0; j < orders.length; j++)
{
output += "<tr><td></td>"; // empty first cell
output += "<td>" + orders[j][0] + "</td>"; // order id
output += "<td>" + orders[j][1] + "</td>"; // order Date
output += "<td>" + orders[j][3] + "</td>"; // product name
output += "<td>" + orders[j][4] + "</td></tr>"; // order quantity, close row
}
}
output += "</table>";
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = output;
}

New Topic/Question
Reply



MultiQuote


|