I believe you can leave your assertion the way it is. Consider this piece of code:
public static void test7 () { String input = "<catalog xmlns='http://www.edankert.com/examples/'>" + "<cd>" + "<artist>Sufjan Stevens</artist>" + "<title>Illinois</title>" + "<src>http://www.sufjan.com/</src>" + "</cd>" + "<cd>" + "<artist>Stoat</artist>" + "<title>Future come and get me</title>" + "<src>http://www.stoatmusic.com/</src>" + "</cd>" + "<cd>" + "<artist>The White Stripes</artist>" + "<title>Get behind me satan</title>" + "<src>http://www.whitestripes.com/</src>" + "</cd>" + "</catalog>"; org.dom4j.XPath xpath = DocumentHelper.createXPath ("/catalog"); HashMap<String,String> map = new HashMap<String,String>(); map.put( "edx", "http://www.edankert.com/examples/"); List<Node> nodes = eval(input, xpath, null); Node node = nodes.get (0); Iterator iter = ((Element)node).elementIterator(); while (iter.hasNext ()) { System.out.println (iter.next ()); } } It will print out the 3 cd elements. The important thing is to provide the default namespace to the XPath engine. Isabelle William Pietri wrote: > Hi! I'm using dom4j's great XPath processing to do extensive unit > testing of XHTML. Changing the pages to be explicitly XHTML broke all my > XPaths, and I'm wondering how to fix that. Ideally, I'd like the default > namespace in my documents to be the default namespace in my XPaths. > > > For starters, let me explain the situation. Consider this simple document: > > <html><head><title>Hi!</title></head><body><p>Hello</p></body></html> > > You could test for the presence of the paragraph like this: > > assertThat(document.selectNodes("//p").size(),is(1)); > > However, suppose I add the proper doctype: > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > And then start the document like this: > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> > > Suddenly, my test fails! The XPath no longer matches. > > > This has been discussed in the archives before. The solution mentioned > is to set it up so that the XPaths have an explicit namespace, and then > to set a namespace map in the DocumentFactory. But for me, that would > require changing hundreds of test assertions, and in a way that would > make them harder to read. > > Is there some way I can fix this without changing my tests? I tried > explicitly telling the DocumentFactory that "" should map to the XHTML > namespace, and in the debugger it looks like the Document object has > that right. But I still can't do a selectNodes call and have it return > anything. > > Any help is appreciated. > > Thanks, > > William > > > > > ------------------------------------------------------------------------- > 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=/ > _______________________________________________ > dom4j-user mailing list > dom4j-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/dom4j-user > ------------------------------------------------------------------------- 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=/ _______________________________________________ dom4j-user mailing list dom4j-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dom4j-user