import java.io.*;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class XPathTest {
 public static void main(String[] args) {
  try {
   DocumentBuilderFactory docFactory =DocumentBuilderFactory.newInstance();
   DocumentBuilder builder = docFactory.newDocumentBuilder();
   Document document = builder.parse(new File("news.xml"));
   XPathFactory factory = XPathFactory.newInstance();
   XPath xpath = factory.newXPath();
   NodeList nodeList = (NodeList) xpath.evaluate( "/news/*", document, XPathConstants.NODESET);
   for (int a = 0; a < nodeList.getLength(); a++) {
    Node node = nodeList.item(a);
   System.out.println(node.getTextContent());
   }
  }
  catch (XPathExpressionException e) {
   e.printStackTrace();
  }
  catch (ParserConfigurationException e) {
   e.printStackTrace();
  }
  catch (SAXException e) {
   e.printStackTrace();
  }
  catch (IOException e) {
   e.printStackTrace();
  }
 }
}
