XML to JSON
This commit is contained in:
@ -1020,7 +1020,7 @@ function delChild(obj)
|
||||
function applyNodeToNode(first, second, name)
|
||||
{
|
||||
if(first===null || second===null || name ===null){
|
||||
console.error("first="+first+" second="+second+" name="+name);
|
||||
log.error("first="+first+" second="+second+" name="+name);
|
||||
return;
|
||||
}
|
||||
//Если есть совпадающие узлы то передаём в рекурсию если нет то просто копируем
|
||||
@ -1057,10 +1057,9 @@ function applyNodeToNode(first, second, name)
|
||||
|
||||
/*function applyObjectToObject(first, second, name){
|
||||
if(first===null || second===null || name ===null){
|
||||
console.error("first="+first+" second="+second+" name="+name);
|
||||
log.error("first="+first+" second="+second+" name="+name);
|
||||
return;
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
function escapeRegExp(str) {
|
||||
@ -1114,39 +1113,97 @@ class TRequest
|
||||
}
|
||||
|
||||
processReqChange(xmlHttpRequest,url,xmlString)
|
||||
{
|
||||
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
|
||||
{
|
||||
if(xmlHttpRequest.responseXML!=null) {
|
||||
//if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
|
||||
// xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
|
||||
let xmldoc = xmlHttpRequest.responseXML;
|
||||
if (xmldoc == null) {
|
||||
alert2(trt('Alert'), trt('Wrong_XML_document') + "!\nXML=(" + xmlHttpRequest.responseText + ')\nURL=(' + url + ')\nxmlString=(' + xmlString + ')');
|
||||
return;
|
||||
}
|
||||
let node = xmldoc.documentElement;
|
||||
if ((node == null) || (node.getAttribute("fn") == null)){
|
||||
alert2(trt('Error'), trt('No_data')+"! \n" + xmlHttpRequest.responseText);
|
||||
}else {
|
||||
let fn = node.getAttribute("fn");
|
||||
if (this.winObj != null) {
|
||||
this.winObj.applyReq(this, fn, node, xmldoc, this.winObj);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
let obj = JSON.parse(xmlHttpRequest.responseText);
|
||||
if(obj==null) {
|
||||
alert2(trt('Alert'), trt('Wrong_JSON_document') + "!\nJSON=(" + xmlHttpRequest.responseText + ')');
|
||||
return;
|
||||
}
|
||||
if(this.winObj!=null)
|
||||
{
|
||||
this.winObj.applyReq(this,obj.fn,obj,null,this.winObj);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
if(confirm(trt('Failed_to_get_data')+"\n URL: "+url+"\n"+xmlHttpRequest.statusText+trt('Repeat_request')+'?'))
|
||||
{
|
||||
this.callServer(url,xmlString);
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*processReqChange(xmlHttpRequest,url,xmlString)
|
||||
{
|
||||
//if (typeof(xmlHttpRequest.readyState)=='undefined' || xmlHttpRequest.readyState == 4)
|
||||
//{
|
||||
if(typeof(xmlHttpRequest.status)=='undefined' || xmlHttpRequest.status == 200)
|
||||
{
|
||||
if(typeof(xmlHttpRequest.responseXML)=='undefined' && xmlHttpRequest.contentType.match(/\/xml/)) //For IE XDomainRequest
|
||||
xmlHttpRequest.responseXML=CreateXMLDOC(xmlHttpRequest.responseText);
|
||||
|
||||
//загрузился xml документ начинаем его разбирать (по id функции в документе)
|
||||
let xmldoc = xmlHttpRequest.responseXML;
|
||||
if(xmldoc==null){
|
||||
alert2(trt('Alert'),trt('Wrong_XML_document')+"!\nXML=("+xmlHttpRequest.responseText+')\nURL=('+url+')\nxmlString=('+xmlString+')');
|
||||
return;
|
||||
}
|
||||
|
||||
let node = xmldoc.documentElement;
|
||||
if((node==null)||(node.getAttribute("fn")==null)) alert(trt('Error')+"\n"+trt('No_data')+"!\n"+xmlHttpRequest.responseText);
|
||||
else
|
||||
{
|
||||
//alert("XML=\n"+getXMLNodeSerialisation(node));
|
||||
let fn = node.getAttribute("fn");
|
||||
if(this.winObj!=null)
|
||||
{
|
||||
//this.winObj.alert("Принятый браузером XML=\n"+getXMLNodeSerialisation(node));
|
||||
/* каждый слушатель должен сам реализовать
|
||||
* if (fn==-1)
|
||||
alert(JSON.stringify(xmlHttpRequest));
|
||||
if(typeof(xmlHttpRequest.responseXML)=='undefined') {
|
||||
if(xmlHttpRequest.contentType.match(/\/xml/)) {
|
||||
xmlHttpRequest.responseXML = CreateXMLDOC(xmlHttpRequest.responseText);
|
||||
if(xmlHttpRequest.responseXML==null) {
|
||||
alert2(trt('Alert'), trt('Wrong_XML_document') + "!\nXML=(" + xmlHttpRequest.responseText + ')\nURL=(' + url + ')\nxmlString=(' + xmlString + ')');
|
||||
return;
|
||||
}
|
||||
//загрузился xml документ начинаем его разбирать (по id функции в документе)
|
||||
let node = xmlHttpRequest.responseXML.documentElement;
|
||||
if((node==null)||(node.getAttribute("fn")==null)) alert(trt('Error')+"\n"+trt('No_data')+"!\n"+xmlHttpRequest.responseText);
|
||||
else
|
||||
{
|
||||
alert(findFirstNode(node,'#cdata-section').nodeValue);
|
||||
}else*/
|
||||
this.winObj.applyReq(this,fn,node,xmldoc,this.winObj);
|
||||
return null;
|
||||
}else if(fn==0) alert(findFirstNode(node,'#cdata-section').nodeValue);
|
||||
let fn = node.getAttribute("fn");
|
||||
if(this.winObj!=null)
|
||||
{
|
||||
this.winObj.applyReq(this,fn,node,xmldoc,this.winObj);
|
||||
return null;
|
||||
}else if(fn==0) alert(findFirstNode(node,'#cdata-section').nodeValue);
|
||||
}
|
||||
|
||||
}else if(xmlHttpRequest.contentType.match(/\/json/)){
|
||||
xmlHttpRequest.responseXML = JSON.parse(xmlHttpRequest.responseText);
|
||||
if(xmlHttpRequest.responseXML==null) {
|
||||
alert2(trt('Alert'), trt('Wrong_JSON_document') + "!\nJSON=(" + xmlHttpRequest.responseText + ')\nURL=(' + url + ')\njsonString=(' + xmlString + ')');
|
||||
return;
|
||||
}
|
||||
//загрузился xml документ начинаем его разбирать (по id функции в документе)
|
||||
let node=xmlHttpRequest.responseXML;
|
||||
if((node==null)||(node.fn==null)) alert(trt('Error')+"\n"+trt('No_data')+"!\n"+xmlHttpRequest.responseText);
|
||||
else
|
||||
{
|
||||
if(this.winObj!=null)
|
||||
{
|
||||
this.winObj.applyReq(this,node.fn,node,null,this.winObj);
|
||||
return null;
|
||||
}else if(fn==0) alert(findFirstNode(node,'#cdata-section').nodeValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
if(confirm(trt('Failed_to_get_data')+"\n URL: "+url+"\n"+xmlHttpRequest.statusText+"\nПовторить запрос?"))
|
||||
@ -1156,7 +1213,7 @@ class TRequest
|
||||
}
|
||||
//}
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
};
|
||||
|
||||
/** Класс асинхронных запросов к серверу
|
||||
|
||||
Reference in New Issue
Block a user