Parse a response with XPath

When you receive an XML response from Adobe Connect, you need to be able to parse it to extract the XML elements you need.

If you are working in a language such as Java™, with an XML parser (such as Xerces or JDOM) installed, you can parse through an XML response, select values from nodes, and then use those values.

Use XPath to parse a response

Write a method that calls one or more actions. Create an instance of the XPath class so that you can use the XPath expressions. Call the actions, read the XML response, and use XPath syntax to select the values you need:
public String scoUrl(String scoId) throws XMLApiException { 
        try { 
            Element e = request("sco-info", "sco-id=" + scoId); 
            if(!(codePath.valueOf(e).equalsIgnoreCase("ok"))) 
                return ""; 
            XPath xpath = XPath.newInstance("//url-path/text()"); 
            String path = ((Text) xpath.selectSingleNode(e)).getText(); 
 
            e = request("sco-shortcuts", null); 
            xpath = XPath.newInstance("//domain-name/text()"); 
            String url = ((Text) xpath.selectSingleNode(e)).getText(); 
 
            return url + "/" + path.substring(1) + "?session=" + breezesession; 
        } catch (JDOMException jde) { 
            throw new XMLApiException(PARSE_ERROR, jde); 
        } 
}

You can also use string pattern matching to check for a status code of ok . A successful action always returns this response:

<?xml version="1.0" encoding="utf-8" ?>  
<results> 
    <status code="ok" />  
</results>

You can check the response for the pattern ok or code="ok" .

// Ethnio survey code removed