dcsimg
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
Thanks for your registration, follow us on our social networks to keep up-to-date