title: How to use Java String variables inside XPath query
body: <p>I have <code>books.xml</code> file which contains author name and book titles. I am using the following code snippet to query <code>books.xml</code>.</p>
  
  <pre><code>XPathFactory factory = XPathFactory.newInstance();
  XPath xpath = factory.newXPath();
  XPathExpression expr 
      = xpath.compile("//book[author= 'Larry Niven']/title/text()");
  </code></pre>
  
  <p>Now instead of directly putting the name in the query if I want to pass it while the program is running as a String variable how to do it. Just putting the string variable name is not working!</p>