try{Object.defineProperty(Array.prototype,"peek",{value:function(){return(this.length>0?this[this.length-1]:undefined)}})}catch(e){}module.exports.ParseWsman=function(j){try{if(!j.childNodes){j=_turnToXml(j)}var g={Header:{}},d=j.getElementsByTagName("Header")[0],h;if(!d){d=j.getElementsByTagName("a:Header")[0]}if(!d){return null}for(var f=0;f0){h=a.childNodes[0].localName;if(h.indexOf("_OUTPUT")==h.length-7){h=h.substring(0,h.length-7)}g.Header.Method=h;g.Body=_ParseWsmanRec(a.childNodes[0])}return g}catch(c){console.error("Unable to parse XML: "+j,c);return null}};function _ParseWsmanRec(g){var c,h={};for(var d=0;d0)){b={Value:c};for(var f=0;f';for(var c in d){if(!d.hasOwnProperty(c)||c.indexOf("__")===0||c.indexOf("@")===0){continue}if(d[c]==null||typeof d[c]==="function"){continue}if(typeof d[c]==="object"&&d[c]["ReferenceParameters"]){f+=""+d[c].Address+""+d[c]["ReferenceParameters"]["ResourceURI"]+"";var h=d[c]["ReferenceParameters"]["SelectorSet"]["Selector"];if(Array.isArray(h)){for(var a=0;a"+h[a]["Value"]+""}}else{f+=""+h.Value+""}f+=""}else{if(Array.isArray(d[c])){for(var a=0;a"+d[c][a].toString()+""}}else{f+=""+d[c].toString()+""}}}f+="";return f}function _treeBuilder(){this.tree=[];this.push=function(a){this.tree.push(a)};this.pop=function(){var a=this.tree.pop();if(this.tree.length>0){var b=this.tree.peek();b.childNodes.push(a);b.childElementCount=b.childNodes.length}return(a)};this.peek=function(){return(this.tree.peek())};this.addNamespace=function(g,d){this.tree.peek().nsTable[g]=d;if(this.tree.peek().attributes.length>0){for(var c=0;c=0;--a){if(this.tree[a].nsTable[b]!=null){return(this.tree[a].nsTable[b])}}return null}}function _turnToXml(a){if(a==null){return null}return({childNodes:[_turnToXmlRec(a)],getElementsByTagName:_getElementsByTagName,getChildElementsByTagName:_getChildElementsByTagName,getElementsByTagNameNS:_getElementsByTagNameNS})}function _getElementsByTagNameNS(b,a){var c=[];_xmlTraverseAllRec(this.childNodes,function(d){if(d.localName==a&&(d.namespace==b||b=="*")){c.push(d)}});return c}function _getElementsByTagName(a){var b=[];_xmlTraverseAllRec(this.childNodes,function(c){if(c.localName==a){b.push(c)}});return b}function _getChildElementsByTagName(a){var c=[];if(this.childNodes!=null){for(var b in this.childNodes){if(this.childNodes[b].localName==a){c.push(this.childNodes[b])}}}return(c)}function _getChildElementsByTagNameNS(c,a){var d=[];if(this.childNodes!=null){for(var b in this.childNodes){if(this.childNodes[b].localName==a&&(c=="*"||this.childNodes[b].namespace==c)){d.push(this.childNodes[b])}}}return(d)}function _xmlTraverseAllRec(c,a){for(var b in c){a(c[b]);if(c[b].childNodes){_xmlTraverseAllRec(c[b].childNodes,a)}}}function _turnToXmlRec(w){try{if(w==null){return null}var m=new _treeBuilder(),r=null,z=w.split("<"),u=[],h=null,g=null;for(var o in z){var A=z[o].split(">"),B=A[0].split(" "),l=B[0];if((l.length>0)&&(l[0]!="?")){if(l[0]!="/"){var a=[],s,t=l.split(" ")[0].split(":"),s=(t.length>1)?t[1]:t[0];Object.defineProperty(a,"get",{value:function(){if(arguments.length==1){for(var i in this){if(this[i].name==arguments[0]){return(this[i])}}}else{if(arguments.length==2){for(var i in this){if(this[i].name==arguments[1]&&(arguments[0]=="*"||this[i].namespace==arguments[0])){return(this[i])}}}else{throw ("attributes.get(): Invalid number of parameters")}}}});m.push({name:l,localName:s,getChildElementsByTagName:_getChildElementsByTagName,getElementsByTagNameNS:_getElementsByTagNameNS,getChildElementsByTagNameNS:_getChildElementsByTagNameNS,attributes:a,childNodes:[],nsTable:{}});if(B.length>0){var v=false;for(var p in B){if(B[p]=="/"){m.peek().namespace=m.peek().name==m.peek().localName?m.getNamespace("*"):m.getNamespace(m.peek().name.substring(0,m.peek().name.indexOf(":")));m.peek().textContent="";r=m.pop();v=true;break}var q=B[p].indexOf("=");if(q>0){var b=B[p].substring(0,q);var d=B[p].substring(q+2,B[p].length-1);var c=m.getNamespace("*");if(b=="xmlns"){m.addNamespace("*",d);c=d}else{if(b.startsWith("xmlns:")){m.addNamespace(b.substring(6),d)}else{var f=b.split(":");if(f.length==2){b=f[1];c=m.getNamespace(f[0])}}}var y={name:b,value:d};if(c!=null){y.namespace=c}m.peek().attributes.push(y)}}if(v){continue}}m.peek().namespace=m.peek().name==m.peek().localName?m.getNamespace("*"):m.getNamespace(m.peek().name.substring(0,m.peek().name.indexOf(":")));if(A[1]){m.peek().textContent=A[1]}}else{r=m.pop()}}}}catch(n){return null}return r};