3 Replies Latest reply on Apr 7, 2010 1:44 AM by 807580

    Using DOM4J XPath

      IM going nuts trying to use DOM4J to query something so simple. Here is the input XML file and the code to run the XPath. If I loop through the document using the annoying element and node map thing it works fine and I can get all the nodes. But I want to run an XPath query right to the information I want. Firs time I tried without the URI nodes and this time I tried it with it. Still no luck.

      XML FILE
      <?xml version="1.0"?>
           <config SERVICE="Service Name">
                <detail name="key">value</detail>
           <config SERVICE="ProcessErrors">
                <detail name="ErrorEmailAddresses">johnsmith@hotmail.com</detail>
           <config SERVICE="TestSQLErrors">
                <detail name="ErrorEmailAddresses">johnsmith@hotmail.com</detail>
      File fXmlFile = new File("n:\\config.xml");
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(fXmlFile);
      XPath xpathNodes = new DefaultXPath("//configs/config[@SERVICE='ProcessErrors']/detail[@name='ErrorEmailAddresses']");
      HashMap<String, String> mapNodes = new HashMap<String,String>();
      Node exceptionNode = (Node)xpathNodes.selectSingleNode(doc);
      exceptionNode is empty. If I run this same query on the same document in XML spy I get the value.???