java parsing soap response with optional nodes -
i need parse soap reponse can have optional nodes. structure this:
queryinvoiceresponse invoicelist invoice - optional, unbounded; type invoice consignee - optional; type consignee address type string name type string tin type string consignor - optional; type consignor address type string name type string tin type string customerjoopparticipants - optional; joopparticipant - optional, unbounded; type joopparticipants productshares share - unbounded; type productshare productnumber - required; type int quantity type decimal tin - required; type string customers customer - unbounded; type customer statuses - optional; status - optional, unbounded; type customertype - type string restriction - enum { 'committent', 'broker', 'lessee', 'joint_activity_participant', 'public_office', 'nonresident', 'individual' } address type string certificatenum type string certificateseries type string name type string tin type string trailer type string deliveryterm - optional; type deliveryterm contractdate type string contractnum type string destination type string exerciseway type string term type string warrant type string warrantdate type string draftid - optional; type long products type productset product - unbounded; type product additional type string applicationnumberincustomsunion type string description - required; type string exciseamount type decimal exciserate type decimal ndsamount - required; type decimal ndsrate type int pricewithtax - required; type decimal pricewithouttax - required; type decimal quantity type decimal turnoversize - required; type decimal unitcode type string unitnomenclature type string unitprice type decimal currencycode - required; type string currencyrate type decimal totalexciseamount - required; type decimal totalndsamount - required; type decimal totalpricewithtax - required; type decimal totalpricewithouttax - required; type decimal totalturnoversize - required; type decimal publicoffice - optional; type publicoffice bik type string iik - required; type string paypurpose - required; type string productcode type string relatedinvoice - optional; type relatedinvoice date - required; type string num - required; type string sellerjoopparticipants - optional; joopparticipant - optional, unbounded; type joopparticipants productshares share - unbounded; type productshare productnumber - required; type int quantity type decimal tin - required; type string sellers seller - unbounded; type seller statuses - optional; status - optional, unbounded; type sellertype - type string restriction - enum { 'committent', 'broker', 'forwarder', 'lessor', 'joint_activity_participant', 'exporter' } address type string bank type string bik type string certificatenum type string certificateseries type string deliverydocdate type string deliverydocnum type string iik type string kbe type string name type string tin - required; type string trailer type string signature type string addinf type string cancelreason type string certificate type string date - required; type string deliverydate type datetime id type long inputdate type datetime invoicetype - required; type invoicetype - type string restriction - enum { 'ordinary_invoice', 'fixed_invoice', 'additional' } registrationnumber type string lastupdatedate type datetime num - required; type string operatorfullname - required; type string signaturetype - required; type signaturetype - type string restriction - enum { 'company', 'operator' } signaturevalid type boolean state type invoicestatetype - type string restriction - enum { 'accepted', 'declined' } status type invoicestatustype - type string restriction - enum { 'created', 'delivered', 'canceled', 'revoked', 'imported', 'draft', 'failed', 'deleted' } turnoverdate - required; type string currpage - required; type int lastblock - required; type boolean rscount - required; type int
as u can see has optinal nodes. use code parse when need 1 node's value, attributes:
public static string getsessionid(document docu){ string sessionid = null; try { documentbuilderfactory dbfactory = documentbuilderfactory.newinstance(); documentbuilder dbuilder = dbfactory.newdocumentbuilder(); document doc = docu; //optional, recommended //read - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work doc.getdocumentelement().normalize(); //system.out.println("root element :" + doc.getdocumentelement().getnodename()); nodelist nlist = doc.getelementsbytagname("ns2:createsessionresponse"); // system.out.println("----------------------------"); (int temp = 0; temp < nlist.getlength(); temp++) { node nnode = nlist.item(temp); //system.out.println("\ncurrent element :" + nnode.getnodename()); if (nnode.getnodetype() == node.element_node) { element eelement = (element) nnode; // system.out.println("sessionid is: " + eelement.getelementsbytagname("sessionid").item(0).gettextcontent()); sessionid = eelement.getelementsbytagname("sessionid").item(0).gettextcontent(); } } } catch (exception e) { e.printstacktrace(); } return sessionid; }
how parse soap response has optional nodes can or cant in soap response?
Comments
Post a Comment