Brian Stechly
2013-11-01 18:21:32 UTC
Hi,
I have been working on this simple code for days and am hoping somebody can point me in the right direction. I cannot get the sObject and it's children to parse correctly in the following:
public static Document XML_SOAP_Data(InputStream xml_in) {
try {
Builder builder = new Builder();
Document response = builder.build(xml_in);
/* response we are expecting
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://soap.someURL.com/out">
<OrganizationId>00Di0000000H88xEAC</OrganizationId>
<ActionId>04ki00000004FCuAAM</ActionId>
<SessionId xsi:nil="true"/>
<EnterpriseUrl>https://na15.salesomeurl.com/services/Soap/c/29.0/00Di0000000H88x</EnterpriseUrl>
<PartnerUrl>https://na15.salesomeurl.com/services/Soap/u/29.0/00Di0000000H88x</PartnerUrl>
<Notification>
<Id>04li00000017ikLAAQ</Id>
<sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
<sf:Id>00vi00000071B8rAAE</sf:Id>
<sf:CampaignId>701i0000000EQMBAA4</sf:CampaignId>
<sf:SOAP_City__c>Washington</sf:SOAP_City__c>
<sf:SOAP_First_Name__c>Lisa Test-C</sf:SOAP_First_Name__c>
<sf:SOAP_Last_Name__c>Rossi</sf:SOAP_Last_Name__c>
<sf:SOAP_Postal_Code__c>20007-3117</sf:SOAP_Postal_Code__c>
<sf:SOAP_State__c>DC</sf:SOAP_State__c>
<sf:SOAP_Street__c>3133 'O' Street NW</sf:SOAP_Street__c>
<sf:School_Name__c>[not provided]</sf:School_Name__c>
<sf:Status>Not Sent</sf:Status>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
*/
Element responseEnvelope = response.getRootElement();
Element responseBody = responseEnvelope.getFirstChildElement("Body","http://schemas.xmlsoap.org/soap/envelope/");
Element fault = responseBody.getFirstChildElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
if (fault == null) { // no fault
Element resNotifications = responseBody.getFirstChildElement("notifications", "http://soap.someURL.com/out");
Elements resOrganizationId = resNotifications.getChildElements("OrganizationId", "http://soap.someURL.com/out");
Elements resActionId = resNotifications.getChildElements("ActionId", "http://soap.someURL.com/out");
Elements resSessionId = resNotifications.getChildElements("SessionId", "http://soap.someURL.com/out");
Elements resEnterpriseUrl = resNotifications.getChildElements("EnterpriseUrl", "http://soap.someURL.com/out");
Elements resPartnerUrl = resNotifications.getChildElements("PartnerUrl", "http://soap.someURL.com/out");
Elements resNotification = resNotifications.getChildElements("Notification", "http://soap.someURL.com/out");
Element aNotification = null;
for (int i = 0; i < resNotification.size(); i++) {
System.out.println("\n NEW Notification \n");
aNotification = resNotification.get(i); System.out.println("\n 1 \n");
Element resId = aNotification.getFirstChildElement("Id", "http://soap.someURL.com/out"); //this works
// ! This is where I am having the issue ! //
// <sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
// <sf:Id>00vi00000071B8rAAE</sf:Id>
Element resSObject = aNotification.getFirstChildElement("sObject", "urn:sobject.enterprise.soap.someurl.com");
//Have tried with and without the line below
resSObject.addNamespaceDeclaration("sf", "urn:sobject.enterprise.soap.someurl.com");
Element resSfId = resSObject.getFirstChildElement("sf:Id", "urn:sobject.enterprise.soap.someurl.com");
// ! Trying to get the sObject and child above to parse ! //
Thanks!
I have been working on this simple code for days and am hoping somebody can point me in the right direction. I cannot get the sObject and it's children to parse correctly in the following:
public static Document XML_SOAP_Data(InputStream xml_in) {
try {
Builder builder = new Builder();
Document response = builder.build(xml_in);
/* response we are expecting
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<notifications xmlns="http://soap.someURL.com/out">
<OrganizationId>00Di0000000H88xEAC</OrganizationId>
<ActionId>04ki00000004FCuAAM</ActionId>
<SessionId xsi:nil="true"/>
<EnterpriseUrl>https://na15.salesomeurl.com/services/Soap/c/29.0/00Di0000000H88x</EnterpriseUrl>
<PartnerUrl>https://na15.salesomeurl.com/services/Soap/u/29.0/00Di0000000H88x</PartnerUrl>
<Notification>
<Id>04li00000017ikLAAQ</Id>
<sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
<sf:Id>00vi00000071B8rAAE</sf:Id>
<sf:CampaignId>701i0000000EQMBAA4</sf:CampaignId>
<sf:SOAP_City__c>Washington</sf:SOAP_City__c>
<sf:SOAP_First_Name__c>Lisa Test-C</sf:SOAP_First_Name__c>
<sf:SOAP_Last_Name__c>Rossi</sf:SOAP_Last_Name__c>
<sf:SOAP_Postal_Code__c>20007-3117</sf:SOAP_Postal_Code__c>
<sf:SOAP_State__c>DC</sf:SOAP_State__c>
<sf:SOAP_Street__c>3133 'O' Street NW</sf:SOAP_Street__c>
<sf:School_Name__c>[not provided]</sf:School_Name__c>
<sf:Status>Not Sent</sf:Status>
</sObject>
</Notification>
</notifications>
</soapenv:Body>
</soapenv:Envelope>
*/
Element responseEnvelope = response.getRootElement();
Element responseBody = responseEnvelope.getFirstChildElement("Body","http://schemas.xmlsoap.org/soap/envelope/");
Element fault = responseBody.getFirstChildElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
if (fault == null) { // no fault
Element resNotifications = responseBody.getFirstChildElement("notifications", "http://soap.someURL.com/out");
Elements resOrganizationId = resNotifications.getChildElements("OrganizationId", "http://soap.someURL.com/out");
Elements resActionId = resNotifications.getChildElements("ActionId", "http://soap.someURL.com/out");
Elements resSessionId = resNotifications.getChildElements("SessionId", "http://soap.someURL.com/out");
Elements resEnterpriseUrl = resNotifications.getChildElements("EnterpriseUrl", "http://soap.someURL.com/out");
Elements resPartnerUrl = resNotifications.getChildElements("PartnerUrl", "http://soap.someURL.com/out");
Elements resNotification = resNotifications.getChildElements("Notification", "http://soap.someURL.com/out");
Element aNotification = null;
for (int i = 0; i < resNotification.size(); i++) {
System.out.println("\n NEW Notification \n");
aNotification = resNotification.get(i); System.out.println("\n 1 \n");
Element resId = aNotification.getFirstChildElement("Id", "http://soap.someURL.com/out"); //this works
// ! This is where I am having the issue ! //
// <sObject xsi:type="sf:CampaignMember" xmlns:sf="urn:sobject.enterprise.soap.someurl.com">
// <sf:Id>00vi00000071B8rAAE</sf:Id>
Element resSObject = aNotification.getFirstChildElement("sObject", "urn:sobject.enterprise.soap.someurl.com");
//Have tried with and without the line below
resSObject.addNamespaceDeclaration("sf", "urn:sobject.enterprise.soap.someurl.com");
Element resSfId = resSObject.getFirstChildElement("sf:Id", "urn:sobject.enterprise.soap.someurl.com");
// ! Trying to get the sObject and child above to parse ! //
Thanks!