JavaScript to parse a soap request -
hi wanto parse following xml file, can see webservice request:
importpackage(packages.java.io); importpackage(packages.java.lang); importpackage(packages.java.util); importpackage(packages.org.w3c.dom); importpackage(packages.com.vordel.circuit); importpackage(packages.com.vordel.common.base64); importpackage(packages.com.vordel.dwe); importpackage(packages.com.vordel.mime); importpackage(packages.com.vordel.trace); importpackage(packages.com.vordel.common.util); importpackage(packages.com.vordel.es); importpackage(packages.com.vordel.es.xes); function invoke(msg) { var container = msg.get ("container"); var policy= msg.get ("policy_accountactivity"); try { var espk = portableespkfactory.newinstance().createportableespk( "<key type='circuitcontainer'>" + "<id field='name' value='"+container+"'/>" + "<key type='filtercircuit'>" + "<id field='name' value='"+policy+"'/>" + "</key>" + "</key>"); // here obtaining reference on policy invoked var circuit = service.getinstance().getlocalpack().cache.getcircuit(espk); // setting dummy context, needed invoke policy afterwards var context = new java.lang.string("defaultcontext"); // xml body var body = xmlbody.locate(msg); var doc = body.getdocument(); var root = doc.getdocumentelement(); var nameelement = "get_account_activity_request"; var nodes = root.getelementsbytagname(nameelement); if ((nodes == null) || (nodes.getlength() <= 0)) { trace.error("there no "+nameelement+" elements found in message"); return false; } var content = new stringbuffer(); var compteur = 1; (i = 0; < nodes.getlength(); i++) { var toprocess = nodes.item(i); if (toprocess == null) continue; // contents of element var children = toprocess.getchildnodes(); trace.debug("getting children"); msg.put("messageidctp",compteur.tostring()); compteur+=1; (j = 0; j < children.getlength(); j++) { var node = children.item(j); if (node.getnodename() == "mob:maxnbrecord") { var childrenmaxnbrecord= node.getchildnodes(); var nodemaxnbrecord= childrenmaxnbrecord.item(0); var value= nodemaxnbrecord.getnodevalue(); msg.put ("account.maxnbrecord" , value.tostring() ) ; } if (node.getnodename() == "mob:startdate") { var childrenstartdate= node.getchildnodes(); var nodestartdate= childrenstartdate.item(0); var value= nodestartdate.getnodevalue(); msg.put ("account.startdate" , value.tostring() ) ; } if (node.getnodename() == "mob:enddate") { var childrenenddate= node.getchildnodes(); var nodeenddate= childrenenddate.item(0); var value= nodeenddate.getnodevalue(); msg.put ("account.enddate" , value.tostring() ) ; } if (node.getnodename() == "mob:minamount") { var childrenminamount= node.getchildnodes(); var nodeminamount= childrenminamount.item(0); var value= nodeminamount.getnodevalue(); msg.put ("account.minamount" , value.tostring() ) ; } if (node.getnodename() == "mob:maxamount") { var childrenmaxamount= node.getchildnodes(); var nodemaxamount= childrenmaxamount.item(0); var value= nodemaxamount.getnodevalue(); msg.put ("account.maxamount" , value.tostring() ) ; invocationengine.invokecircuit(circuit, context, msg); } } } } catch (exp) { trace.error(exp); } return true; } <soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:acc="url" xmlns:mob="url"> <soapenv:header/> <soapenv:body> <acc:get_account_activity_requestflow> <mob:requestheader> <mob:requestid>1</mob:requestid> <mob:servicename>ws_webservicename</mob:servicename> <mob:timestamp>2015-04-22t18:12:06.84585</mob:timestamp> </mob:requestheader> <acc:get_account_activity_request> <mob:accountid> <mob:code1>0003</mob:code1> <mob:code2>552</mob:code2> <mob:code3>056897</mob:code3> </mob:accountid> <!--optional:--> <mob:maxnbrecord>1</mob:maxnbrecord> <mob:startdate>2015-04-22t18:12:06.00000</mob:startdate> <mob:enddate>2015-04-22t19:12:06.00000</mob:enddate> <!--optional:--> <mob:minamount>0000.0000</mob:minamount> <!--optional:--> <mob:maxamount>6000.0000</mob:maxamount> </acc:get_account_activity_request> </acc:get_account_activity_requestflow> </soapenv:body> </soapenv:envelope>
my script gathering following elements come in immediate level under acc:get_account_activity_request.
but issue dont know how retrieve elements code1, 2 , 3 come inside tag:
when "if (node.getnodename() == "mob:code1")" element not found.
any advise hugely appreciated
Comments
Post a Comment