As you probably know, an XPath 2.0 expression returns a sequence of items (nodes and atomic values). The following code shows you how to read from a sequence of items in Saxon 8. The code identifies the nodes and atomic values and calls the correct methods for showing them.
...List L=null;...try{ //this XPath expression returns a sequence of nodes L=XPE.evaluate("/company/departments/"); //this XPath expression returns an atomic value //L=XPE.evaluate("5 instance of xs:integer"); }catch(net.sf.saxon.trans.XPathException e) {System.out.println(e.getMessage());} //processing the resulted sequence if(L!=null) { for(Iterator iter=L.iterator();iter.hasNext();) { Object obj=(Object)iter.next(); if(obj instanceof NodeInfo) { NodeInfo NI=(NodeInfo)obj; String info=net.sf.saxon.type.Type.displayTypeName(NI); System.out.println("INFO:["+info+"]"); System.out.println("VALUE:["+NI.getStringValue()"]"); } else { String val=String.valueOf(obj); System.out.println("ATOMIC VALUE:"+val); } } }}