When you send an XML request to Adobe Connect, the server returns an XML response. You need to parse the response and extract values, including status codes. One way to parse the response is to use XPath to traverse XML elements (see the XPath tutorial at w3schools.com for more information).


See the sample file XMLApiAdapter.java.

As an example, this is the response from sco-shortcuts:

 <?xml version="1.0" encoding="utf-8" ?>  
     <status code="ok" />  
         <sco tree-id="4930295" sco-id="2006258748" type="my-courses"> 
         <sco tree-id="4930293" sco-id="2006258749" type="my-events"> 

Extract values

The getShortcuts method calls sco-shortcuts and parses the response using XPath. This is an example of how to extract a list of sco elements and the sco-id of each:

 public List getShortcuts() throws XMLApiException { 
     try { 
         Element e = request("sco-shortcuts", null); 
         List scosXml = XPath.selectNodes(e, "//sco"); 
         List scos = new ArrayList(); 
         XPath id = XPath.newInstance("./@sco-id"); 
         for (Iterator i = scosXml.iterator(); i.hasNext();) { 
             Element s = (Element) i.next(); 
             SCO sco = getSco(id.valueOf(s)); 
             if(null != sco) 
         return scos; 
     } catch (JDOMException jde) { 
             throw new XMLApiException(PARSE_ERROR, jde); 

Extract a status code

Your application also needs to parse both successful and unsuccessful responses for status codes. For example, when a user calls an action without sufficient permission, the error response has a status element with both code and subcode attributes:

 <?xml version="1.0" encoding="utf-8" ?>  
     <status code="no-access" subcode="denied" /> 

These lines in the createXPaths method parse for the values of code and subcode:

 codePath = XPath.newInstance("//status/@code"); 
 subcodePath = XPath.newInstance("//status/@subcode");

In the sample, the createXPaths method is called when you create an instance of XMLApiAdapter. The getStatus method then uses codePath and subcodePath to return the code and subcode values, separated by a hyphen:

 private String getStatus(Element el) throws JDOMException { 
         String code = codePath.valueOf(el); 
         String subcode = subcodePath.valueOf(el); 
         StringBuffer status = new StringBuffer(); 
         if(null != code && code.length() > 0) 
         if(null != subcode && subcode.length() > 0) 
             status.append(" - " + subcode); 
         return status.toString(); 

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy