1 function resetStatus(){
5 function showMsg(msg,color){
6 $("#node-validate-result").html(msg);
7 $("#node-validate-result")
12 function getAttributeValue(xmlStr,attribute){
17 var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
18 var myArray = myRe.exec(xmlStr);
19 if(myArray != null && myArray[1] != null){
31 var processedNode = "";
34 function processNode(xmlNode){
35 if(xmlNode == null) return;
36 if(xmlNode.nodeName != "parsererror" && xmlNode.nodeName != "#text"){
37 processedNode = xmlNode.nodeName;
39 //console.log("processedNode:" + processedNode);
40 switch(xmlNode.nodeType){
44 //console.log(xmlNode.nodeName);
45 //console.dir(xmlNode.nodeName);
46 if(xmlNode.nodeName == "parsererror"){
47 //var nearNode = xmlNode.previousSibling != null ?xmlNode.previousSibling.nodeName : xmlNode.parentNode.nodeName;
48 console.log("Error parsing xml after node " + processedNode);
49 var msg = "error parsing XML after element <" + processedNode + "> Element#" + elementCount;
54 processedNode = xmlNode.nodeName;
55 var attrs = xmlNode.attributes;
56 for(var i=0;i<attrs.length;i++){
57 //console.log("Attribute:" + attrs[i].nodeName);
58 //console.log("Value:" + attrs[i].value);
59 if(attrs[i].nodeName != "value" && attrs[i].value == ""){
62 var prevSibling = xmlNode.previousSibling;
63 if(prevSibling != null && prevSibling != undefined){
64 msg = "element <" + xmlNode.nodeName + "> attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
66 msg = "element <" + xmlNode.nodeName + "> attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
69 msg = "element <" + xmlNode.nodeName + "> attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
71 //console.log("element <" + xmlNode.nodeName + "> attribute '" + attrs[i].nodeName + "' is not set.Element#" + elementCount);
75 var childNodes = xmlNode.childNodes;
76 for(var k=0;k<childNodes.length;k++){
77 processNode(childNodes[k]);
82 //console.log(xmlNode.nodeName);
86 //console.log(xmlNode.nodeValue);
90 console.log("CDATA_SECTION_NODE");
93 //ENTITY_REFERENCE_NODE
94 console.log("ENTITY_REFERENCE_NODE");
98 console.log("ENTITY_NODE");
101 //PROCESSING_INSTRUCTION_NODE
102 console.log("PROCESSING_INSTRUCTION_NODE");
106 console.log("COMMENT_NODE");
110 console.log("DOCUMENT_NODE");
114 console.log("DOCUMENT_TYPE_NODE");
118 console.log("DOCUMENT_FRAGMENT_NODE");
122 console.log("DOCUMENT_FRAGMENT_NODE");
127 function validateFinalXML(xmlStr){
134 //console.log("In validateXML xmlStr:" + xmlStr);
135 if(xmlStr == null || xmlStr == "") return true;
136 xmlStr = xmlStr.trim();
139 if (window.DOMParser){
141 var parser=new DOMParser();
142 xmlDoc=parser.parseFromString(xmlStr,'text/xml');
143 //console.log("Not IE");
144 var n = xmlDoc.documentElement.nodeName;
147 console.log("Error parsing");
151 console.log("Error parsing" +e);
158 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
160 xmlDoc.loadXMLString(xmlStr);
162 console.log("Error parsing" +e);
167 //console.dir(xmlDoc);
168 processNode(xmlDoc.documentElement);
171 console.log("Validation Successful");
172 RED.notify("<strong>XML validation</strong>: SUCCESS","success");
174 console.log("Errors found. ");
175 RED.notify("<strong>XML validation</strong>: FAILED","error");
178 console.log("error:" +e);
179 RED.notify("<strong>XML validation</strong>: FAILED","error");
186 function validateXML(xmlStr){
193 //console.log("In validateXML xmlStr:" + xmlStr);
194 //var xmlStr = $("#node-input-xml-editor").text();
195 if(xmlStr == null || xmlStr == undefined){
196 xmlStr = $("#node-input-xml-editor").text();
198 if(xmlStr == undefined) return false;
199 //console.dir($("#node-input-xml-editor"));
200 //console.log("xmlStr:" + xmlStr);
201 xmlStr = xmlStr.trim();
206 xmlStr = xmlStr.replace(re,'');
207 var regex = /(<)([\w-]+)(.*)?/;
208 var match = regex.exec(xmlStr);
210 if(match[1] != undefined && match[2] != undefined){
215 showMsg("startTag not found.","red");
222 //console.log(xmlStr);
225 showMsg("XML not found","red");
228 endTag = "</" + startTag + ">";
230 if(xmlStr.indexOf(endTag) != -1){
232 showMsg("Error: End tag </" + startTag + "> must not be included.","red");
233 console.log("End tag " + endTag + " must not be included.");
237 //var xmlTopStr = "<?xml version='1.0' encoding='UTF-8'?>\n" ;
238 //xmlStr = xmlTopStr + xmlStr;
239 //xmlStr = xmlStr.replace(/'/g,"\"");
240 xmlStr+= "\n" + endTag;
241 xmlStr = xmlStr.trim();
242 //console.log("xmlStr:" + xmlStr);
244 if (window.DOMParser){
246 var parser=new DOMParser();
247 xmlDoc=parser.parseFromString(xmlStr,'text/xml');
248 //console.log("Not IE");
249 var n = xmlDoc.documentElement.nodeName;
252 showMsg("Error parsing","red");
253 console.log("Error parsing");
257 console.log("Error parsing" +e);
264 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
266 xmlDoc.loadXMLString(xmlStr);
268 console.log("Error parsing" +e);
273 //console.dir(xmlDoc);
274 processNode(xmlDoc.documentElement);
276 showMsg("Validation Successful","green");
278 showMsg("Errors found. <a onclick='javascript:showErrors()'>show errors</a>","red");
279 console.log("Errors found. ");
282 console.log("error:" +e);
290 function showErrors() {
291 //var sourceField = event != null ?event.srcElement:event.target;
292 //console.dir(sourceField);
293 //sourceField.style.backgroundColor="skyblue";
294 //var leftVal = event.target.offsetLeft ;
295 //alert(topVal + ":" + leftVal);
297 //var pos = event.target;
298 //var topVal = event.target.offsetTop + topPosition ;
299 //var topVal = event.target.offsetTop +75;
300 var htmlStr="<div id='error-list-div'><table id='errTable' border='1'><tr><th>Error List</th></tr>";
301 for(var i=0;errList != null && i<errList.length;i++){
303 htmlStr += "<tr><td>" + errSeq + ")" + errList[i] + "</td></tr>";
305 htmlStr += "</table></div>";
306 //var prevHtml = $("#tab-info").html();
307 //htmlStr += "<input type='button' value='Hide Errors' onclick=\"closeShowErrors('" + prevHtml + "')\" >";
308 //$('#show-errors-div').html(htmlStr);
309 //$("#tab-info").html(prevHtml + htmlStr);
311 //$('<div></div>').dialog({
312 $('#show-errors-dialog').dialog({
314 title: "XML Error List ",
317 $(this).html(htmlStr);
321 $(this).dialog("close");
324 }); // end dialog div