title: XML parsing using SAX by xpath
body: <p>i am trying to do XML parsing using SAX by using xpath. but when i try for getting data for multiple nodeset it do not give that.</p>
  
  <pre><code>  import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
  
    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathExpression;
    import javax.xml.xpath.XPathExpressionException;
    import javax.xml.xpath.XPathFactory;
  
    import org.apache.xpath.NodeSet;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
  
  
    public class XPathEvaluator{
  
  
     public void evaluateDocument(File xmlDocument){
  
      try{
   XPathFactory factory=XPathFactory.newInstance();
   XPath xPath=factory.newXPath();
   InputSource inputSource=new InputSource(new FileInputStream(xmlDocument));
   XPathExpression         
  
    xPathExpression=xPath.compile("/catalog/journal/article[@date='January-2004']/title");
  String title=xPathExpression.evaluate(inputSource);
  System.out.println("Title: "+ title);
  
   inputSource=new InputSource(new FileInputStream(xmlDocument));
  String publisher=xPath.evaluate("/catalog/journal/@publisher", inputSource);
  System.out.println("Publisher:"+ publisher);    
  
  String expression="/catalog/journal[@title='Java Technology']/article";
  NodeSet nodes = (NodeSet) xPath.evaluate(expression, inputSource,XPathConstants.NODESET);    
  NodeList nodeList=(NodeList)nodes;   
  System.out.println("node List"+nodeList);
    }
    catch(IOException  e){}
   catch(XPathExpressionException e){}
  
   }
  
  
   public static void main(String[] argv){
  
  
   XPathEvaluator evaluator=new XPathEvaluator();
  
   File xmlDocument=new File("e://catalog-modified.xml");
   evaluator.evaluateDocument(xmlDocument);
  
   }
  
    }
  </code></pre>
  
  <p>my catalog-modified.xml is as follows</p>
  
  <pre><code>       &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;catalog xmlns:journal="http://www.w3.org/2001/XMLSchema-Instance"&gt; 
          &lt;journal:journal title="XML" publisher="IBM  developerWorks"&gt;       
      &lt;article journal:level="Advanced"   date="February-2003"&gt;   
                &lt;title&gt;Design XML Schemas Using UML&lt;/title&gt;          
                &lt;author&gt;Ayesha Malik&lt;/author&gt;   
      &lt;/article&gt;     
  &lt;/journal:journal&gt; 
   &lt;journal title="Java Technology" publisher="IBM     
        developerWorks"&gt;             
   &lt;article level="Intermediate"  date="January-2004" 
        section="Java Technology"&gt;                      
     &lt;title&gt;Service Oriented Architecture Frameworks
         &lt;/title&gt;                  
         &lt;author&gt;Naveen Balani       
         &lt;/author&gt;               
      &lt;/article&gt;  
      &lt;article level="Advanced" date="October-2003"  section="Java Technology"&gt;                 
         &lt;title&gt;Advance DAO Programming&lt;/title&gt;                   
        &lt;author&gt;Sean Sullivan&lt;/author&gt;               
     &lt;/article&gt;    
      &lt;article level="Advanced" date="May-2002"  section="Java Technology"&gt;     
         &lt;title&gt;Best Practices in EJB Exception Handling   &lt;/title&gt;          
         &lt;author&gt;Srikanth Shenoy      
         &lt;/author&gt;      
       &lt;/article&gt; 
  &lt;/journal&gt; 
  </code></pre>
  
  <p></p>
  
  <p>if i try to call this do not show any nodeset for this .</p>