Dom4j XPath not working parsing xhtml document?

Try declaring the xhtml namespace to the xpath, e.g. Bind it to the prefix x and use x:html/x:body as XPath expression (see also this article which is however for Groovy, not for plain Java). Probably something like the following should do it in Java.

Try declaring the xhtml namespace to the xpath, e.g. Bind it to the prefix x and use //x:html/x:body... as XPath expression (see also this article which is however for Groovy, not for plain Java). Probably something like the following should do it in Java: DefaultXPath xpath = new DefaultXPath("//x:html/x:body/..."); Map namespaces = new TreeMap(); namespaces. Put("x","http://www.w3.org/1999/xhtml"); xpath.

SetNamespaceURIs(namespaces); list = xpath. SelectNodes(document); (untested).

This worked perfectly! I didn't realize you could do that. I also had an extra div that I needed in the path.

But I tried it again without the x: and it did not work that way so your solution did it. I figured that parsing xhtml had issues vs normal xml. – Matt Phillips Sep 1 '10 at 22:06.

I've found long literal XPath expressions hard to debug, as it's easy for my eyes to get tricked... so I break them down until it DOES work and then build back up again.

Thats what I was trying to do. Thats how I caught the missing div. But unfortunately I still needed Andre's answer in order to make the path work even after I had the elements in the right order – Matt Phillips Sep 1 '10 at 22:15 Ah, yes... I'd missed the 'xhtml' part, so if you have a namespace in the file, you'd definitely need it.

– Rodney Gitzel Sep 2 '10 at 17:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions