Read from a Sequence of Items in Saxon 8

Read from a Sequence of Items in Saxon 8

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);         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);         }      }                       }}
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist