I connect to Webex and retrieve the timezone list (XML with namespaces) and try to parse response via res.getBodyDocument()
or doc.load
but I only get document[]
. I have read a lot of other similar questions but the answers do not work for the XML response I get.
Apex code:
Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
string EndPoint = 'https://testco.webex.com/WBXService/XMLService'; // Endpoint depending on site
req.setEndpoint( EndPoint );
req.setMethod('GET');
req.setBody(requestBodyXML);
req.setHeader('Content-Type', 'application/xml');
res = http.send(req);
string xmlResponse = res.getBody();
system.debug('xml: '+ xmlResponse);
Dom.Document doc = res.getBodyDocument();
/*Dom.Document domDoc = new Dom.Document();
domDoc.load(xmlResponse); */
system.debug('doc: '+ domDoc);
Dom.XMLNode timeZone = domDoc.getRootElement();
system.debug('tz: '+ timeZone.getName());
Sample XML:
<?xml version="1.0" encoding="UTF-8"?>
<serv:message xmlns:serv="http://www.webex.com/schemas/2002/06/service" xmlns:com="http://www.webex.com/schemas/2002/06/common" xmlns:ns1="http://www.webex.com/schemas/2002/06/service/site" xmlns:event="http://www.webex.com/schemas/2002/06/service/event">
<serv:header>
<serv:response>
<serv:result>SUCCESS</serv:result>
<serv:gsbStatus>PRIMARY</serv:gsbStatus>
</serv:response>
</serv:header>
<serv:body>
<serv:bodyContent xsi:type="ns1:lstTimeZoneResponse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:timeZone>
<ns1:timeZoneID>0</ns1:timeZoneID>
<ns1:gmtOffset>720</ns1:gmtOffset>
<ns1:description>GMT+12:00, Dateline (Marshall Islands)</ns1:description>
<ns1:shortName>Marshall Islands</ns1:shortName>
<ns1:hideTimeZoneName>false</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
</ns1:timeZone>
<ns1:timeZone>
<ns1:timeZoneID>1</ns1:timeZoneID>
<ns1:gmtOffset>-660</ns1:gmtOffset>
<ns1:description>GMT-11:00, Samoa (Samoa)</ns1:description>
<ns1:shortName>Samoa</ns1:shortName>
<ns1:hideTimeZoneName>true</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
</ns1:timeZone>
<ns1:timeZone>
<ns1:timeZoneID>2</ns1:timeZoneID>
<ns1:gmtOffset>-600</ns1:gmtOffset>
<ns1:description>GMT-10:00, Hawaii (Honolulu)</ns1:description>
<ns1:shortName>Honolulu</ns1:shortName>
<ns1:hideTimeZoneName>true</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
</ns1:timeZone>
<ns1:timeZone>
<ns1:timeZoneID>3</ns1:timeZoneID>
<ns1:gmtOffset>-540</ns1:gmtOffset>
<ns1:description>GMT-09:00, Alaska (Anchorage)</ns1:description>
<ns1:shortName>Anchorage</ns1:shortName>
<ns1:hideTimeZoneName>false</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
<ns1:standardLabel>Standard</ns1:standardLabel>
<ns1:daylightLabel>Daylight</ns1:daylightLabel>
</ns1:timeZone>
<ns1:timeZone>
<ns1:timeZoneID>4</ns1:timeZoneID>
<ns1:gmtOffset>-480</ns1:gmtOffset>
<ns1:description>GMT-08:00, Pacific (San Francisco)</ns1:description>
<ns1:shortName>San Francisco</ns1:shortName>
<ns1:hideTimeZoneName>false</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
<ns1:standardLabel>Standard</ns1:standardLabel>
<ns1:daylightLabel>Daylight</ns1:daylightLabel>
</ns1:timeZone>
<ns1:timeZone>
...
<ns1:timeZoneID>156</ns1:timeZoneID>
<ns1:gmtOffset>420</ns1:gmtOffset>
<ns1:description>GMT+07:00, Novosibirsk (Novosibirsk)</ns1:description>
<ns1:shortName>Novosibirsk</ns1:shortName>
<ns1:hideTimeZoneName>false</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
</ns1:timeZone>
<ns1:timeZone>
<ns1:timeZoneID>157</ns1:timeZoneID>
<ns1:gmtOffset>120</ns1:gmtOffset>
<ns1:description>GMT+02:00, Romania (Bucharest)</ns1:description>
<ns1:shortName>Bucharest</ns1:shortName>
<ns1:hideTimeZoneName>false</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
<ns1:daylightLabel>Daylight</ns1:daylightLabel>
</ns1:timeZone>
<ns1:timeZone>
<ns1:timeZoneID>158</ns1:timeZoneID>
<ns1:gmtOffset>-300</ns1:gmtOffset>
<ns1:description>GMT-05:00, Eastern (Toronto)</ns1:description>
<ns1:shortName>Toronto</ns1:shortName>
<ns1:hideTimeZoneName>false</ns1:hideTimeZoneName>
<ns1:fallInDST>false</ns1:fallInDST>
<ns1:standardLabel>Standard</ns1:standardLabel>
<ns1:daylightLabel>Daylight</ns1:daylightLabel>
</ns1:timeZone>
</serv:bodyContent>
</serv:body>
</serv:message>
jsonResponse
.