Issue with XQuery to retrieve life cycle change date

I have a cx with the desire to retrieve the lifecycle change date, when the life cycle moves from one state to another. I have been provided the following sample code, but I am having an error that is thrown from the java code related to the XQuery. I am looking for assistance to finalize this test code and then incorporate similar code into a larger program and return the dates based on a loop with keys. Is there anyone that can suggest a way to verify the query?

I am not familiar with the Tamino XQuery tool and do not have the knowledge to determine the cause of the issue. Any assistance would be appreciated…

Code:

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import com.softwareag.xqj.extension.TXQDataSourceFactory;
import com.softwareag.xqj.utils.XQItemTypeHelper;

import javax.xml.namespace.QName;
//import javax.xml.soap.Node;
import org.w3c.dom.;
import javax.xml.xquery.
;
import org.apache.log4j.Logger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.log4j.PropertyConfigurator;

public class XXXXX {

/**
 * @param args
 */
static Logger logger = Logger.getLogger(PayloadPurger.class.getName());

public static void main(String[] args) throws Exception {
	// Get LifeCycle Change Date Information via XQuery
	String findLifeCycleQuery = "{-- select events --}"
			+ " declare namespace ns = \"http://namespaces.CentraSite.com/Schema/jaxr\""
			+ " declare variable $registryKey as xs:string external"
			+ " declare namespace xs = \"http://www.w3.org/2001/XMLSchema\""
			+ " let $lc := (for $obj in input()/ns:auditableEvent"
			+ "    where $obj/ns:registryObject = 'uddi:c3af6bce-2cc0-11e6-b874-b40e5a7c3dea'"
			+ "    and $obj/ns:eventType = 'LCSTATECHANGE'" 
			+ " return $obj)" 
			+ "let $max:= max($lc/ns:timeStamp)"
			+ "for $obj in $lc" 
			+ " where $obj/ns:timeStamp = $max" 
			+ "return $obj";