From: Stephen G. W. <sg...@no...> - 2008-07-29 00:05:39
|
I'll even include the code I'm testing with. import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import org.cyberneko.html.parsers.DOMParser; import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class Test4 { public static void main(String[] args) { try { XPathFactory xpFactory = XPathFactory.newInstance(); XPath xpath = xpFactory.newXPath(); String expression = "//title"; XPathExpression xpathExpression = xpath.compile(expression); DOMParser parser = new DOMParser(); parser.setFeature("http://xml.org/sax/features/namespaces", false); parser.parse("./test2.html"); Document doc = parser.getDocument(); Object result = xpathExpression.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { System.out.println(nodes.item(i).getNodeValue()); } } catch(Exception e) { e.printStackTrace(); } } } Test HTML <html> <head> <title>Test Page</title> </head> </body> <p>Foo</p> </body> </html> Returns an empty node set regardless of what I use for expression. I was originally using a more complex HTML but figured I'd simplify things until I got something working. I've also tried the method of using XPath included in the sample application ApplyXPathDOM in the Xalan package. However the compiled expression method is more ideal for my appication. Thanks ----------------------------------------------------------- - stephen.g.walizer - http://node777.net - sg...@no... ----------------------------------------------------------- On Jul 28, 2008, at 8:15 PM, Jacob Kjome wrote: > It would help if you provide an example document, an XPath > expression, and the > node you expect it to match. > > Jake > > Stephen G. Walizer wrote: >> Is there some incompatibility between NekoHTML and XPath as >> implemented by Xalan? I have tried several different methods of >> getting XPath expressions to work on NekoHTML produced documents and >> am having no luck. I can traverse the generated DOM tree, but XPATH >> expressions never produce any results. >> >> I have tried using both a compiled XPathExpression as well as an >> XPathEvaluator with no luck. >> >> I am using NekoHTML 1.9.8 and Xalan-J 2.7.1. >> >> Thank You, >> ----------------------------------------------------------- >> - stephen.g.walizer - http://node777.net - sg...@no... >> ----------------------------------------------------------- > > > ---------------------------------------------------------------------- > --- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > nekohtml-user mailing list > nek...@li... > https://lists.sourceforge.net/lists/listinfo/nekohtml-user |