如何从xml中检索特定子节点值并与javascript中用户输入的值进行比较
用于从用户获取值并检查供应商名称的脚本。
有没有办法根据childnode名称进行检索?
C:\Users\ANONYMOUS>npm run compile:sass
npm ERR! path C:\Users\ANONYMOUS\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\ANONYMOUS\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ANONYMOUS\AppData\Roaming\npm-cache_logs\2018-06-17T05_39_21_109Z-debug.log C:\Users\ANONYMOUS>
XML文件将用户输入的值与supplierName进行比较,如果相同甚至部分打印产品pid,供应商sid和supplierName
function displayAllDetails() {
var userProvidedValue =document.getElementById("textfield").value;
console.log(userProvidedValue);
var allsuppliers = [];
var supplier = [];
var product=[];
var detail =[];
var xhttp = new XMLHttpRequest();
//Open the file
xhttp.open("GET", "products.xml", false);
//Send the request
xhttp.send();
// Read data
var length = xhttp.responseXML.getElementsByTagName("product").length;
product = xhttp.responseXML.getElementsByTagName("product")
title="";
for(var i = 0; i < length ; i++){
var addsupplier=product[i].attributes[0].nodeValue;
console.log(product[i].attributes[0].nodeValue);
for (var j = 0; j < product[i].childNodes.length; j++) {
detail = product[i].childNodes[j];
if(detail.contains("supplier")){
console.log("LUCK");
}
console.log(detail);
}
console.log(addsupplier);
allsuppliers[i] = addsupplier;
}
console.log(allsuppliers);
}