You need to sign in to do that
Don't have an account?
Need help parsing returned XML.
I need to pull just the 'ObjectID' and all I get is a blank value, what am I doing wrong.
here is the returned XML:
<soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/ xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AddFolderResponse xmlns="http://AgileWebservices">
<AddFolderResult>
<ObjectID>109614</ObjectID>
</AddFolderResult>
</AddFolderResponse>
</soap:Body>
</soap:Envelope>
Here is my code:
global class docshare
{
WebService static string invokeExternalWs(integer numOne, integer numTwo)
{
HttpRequest req = new HttpRequest();
req.setEndpoint('https://xxxxxxx'); // for security I have blanked this out
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml; charset=utf-8');
req.setHeader('SOAPAction', 'http://AgileWebservices/AddFolder');
string b = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:agil="http://AgileWebservices"><soapenv:Header/><soapenv:Body><agil:AddFolder><agil:user>lapispw</agil:user><agil:password>lapispw</agil:password><agil:folderName>Mikes fifth test</agil:folderName><agil:objectid>25953</agil:objectid></agil:AddFolder></soapenv:Body></soapenv:Envelope>';
req.setBody(b);
Http http = new Http();
try {
//Execute web service call here
String xObjectID ='';
String soapNS = 'http://schemas.xmlsoap.org/soap/envelope/';
HTTPResponse res = http.send(req);
Dom.Document doc = res.getBodyDocument();
Dom.XMLNode root = doc.getRootElement();
for(dom.XmlNode node : doc.getRootElement().getChildElements()) {
xObjectID = node.getName();
if(node.getName()== 'AddFolderResult') {
xObjectID = node.getChildElement('ObjectID', soapNS).getText();
}
}
return res.getBody();
} catch(System.CalloutException e){
return 'ERROR:' + e;
}
}
}