Home | Categories | Sources | Sites | Languages | About
Note: The project has been discontinued
Using XPath with namespaced documents in dom4j
In dom4j, once you have parsed a document, you can execute XPath expressions like so: List list = doc.selectNodes("/path/to/elements/you/want"); The doc.selectNodes function is a thin wrapper around the jaxen XPath library. This saves you from having to write: XPath xp = new org.jaxen.dom.Dom4jXPath("/path/to/elements/you/want"); List list = xp.execute(doc); However, if the document uses namespaces, you have to tell jaxen about them, or you won't have any way of specifying namespaced elements. Until yesterday, I thought the only way to do this was: XPath xp = new org.jaxen.dom.Dom4jXPath("/x:path/x:to/x:elements/x:you/x:want"); xp.addNamespace("x", "http://example.org/some-random-namespace"); List list = xp.execute(doc); This is a pain in the ass - three lines of code every time you want to use XPath! I did it this way for a little while, but finally got sick of it yesterday and dug through the dom4j code until eventually finding out how to do it properly: Map namespaces = new ...
14:21:24 February 8, 2006, Wednesday (PST) Source: Second p0st

Additional Info

First Fetched: 09:33:20 02/11/2006
Last Updated: 12:32:43 02/17/2006