Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Advanced
Jan 30, 2007

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)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);
         }
      }                    
   }
}
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap