public with sharing class domXmlParsing {
//method to parse xml file
public static string walkThrough(){
//XML string to parse
String response = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">'
+ '<S:Body>'
+ '<wss:createPendingTicketResponse xmlns:wss="http://www.boomi.com/connector/wss">'
+ '<wss:createPaymentTransctionLogResponse/>'
+ '<PendingTicket xmlns:pay="http://www.boomi.com/v1b/Payment">'
+ '<pay:Response>'
+ '<pay:R10TillID>test001</pay:R10TillID>'
+ '<pay:R10SequenceNumber>test002</pay:R10SequenceNumber>'
+ '<pay:SFTnxId>test003</pay:SFTnxId>'
+ '<pay:R10TnxID>'+ 'TESTME' +'</pay:R10TnxID>'
+ '<pay:Org>test004</pay:Org>'
+ '</pay:Response>'
+ '</PendingTicket>'
+ '</wss:createPendingTicketResponse>'
+ '</S:Body>'
+ '</S:Envelope>';
//dom
Dom.Document doc = new Dom.Document();
//string
string result;
//load document
doc.load(response);
Dom.XMLNode envelope = doc.getRootElement();
system.debug('!!!!!!!!! value of envelope' + envelope);
//body
Dom.XMLNode body = envelope.getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/');
system.debug('@@@@@ value of body' + body);
//child element of createPendingTicketResponse
Dom.XMLNode createPendingTicketResponse = body.getChildElement('createPendingTicketResponse', 'http://www.boomi.com/connector/wss');
system.debug('@@@@@ value of createPendingTicketResponse' + createPendingTicketResponse);
//child element of createPaymentTransctionLogResponse
Dom.XMLNode createPaymentTransctionLogResponse = createPendingTicketResponse.getChildElement('createPaymentTransctionLogResponse', 'http://www.boomi.com/connector/wss');
system.debug('@@@####@@ value of createPaymentTransctionLogResponse' + createPaymentTransctionLogResponse);
//child element of pending Ticket
Dom.XMLNode PendingTicket = createPendingTicketResponse.getChildElement('PendingTicket', null);
system.debug('@@@####@@ value of PendingTicket' + PendingTicket);
//child element of Response
Dom.XMLNode Respon = PendingTicket.getChildElement('Response', 'http://www.boomi.com/v1b/Payment');
system.debug('@@@####@@ value of Response' + Respon);
//child element of R10TnxID
Dom.XMLNode R10TnxID = Respon.getChildElement('R10TnxID', 'http://www.boomi.com/v1b/Payment');
system.debug('@@@####@@ value of R10TnxID' + R10TnxID);
//here is the value in R10TnxID
result = R10TnxID.getText();
system.debug('@@@####@@ value of result' + result);
return result;
}
}
Comments
Post a Comment