Hi Chris ----- Original Message ----- From: "James Strachan" <[EMAIL PROTECTED]> > Hey Chris > > Just a thought, what if DocumentFactory had a way of > registering a NamespaceContext or a namespace URI Map > with it, then you could register your normal > namespaces once and never have to worry about such > things again. > > e.g. if you were to register your preferred namespace > URIs with the singleton DocumentFactory, then > everthing should see it I think.
I've added this to CVS. So now there is a setXPathNamespaceUris(Map) method on DocumentFactory where you can register whatever namespace prefixes -> uri mappings you like, then when XPath expressions are evaluated on documents associated with the DocumentFactory the namespace prefixes will be used. I've added a test case to org.dom4j.TestNamespace called testNamespaceUriMap() which demonstrates this in action. Here's a snippet of code that demonstrates it in action... // register namespace prefix->uri mappings with factory Map uris = new HashMap(); uris.put( "x", "fooNamespace" ); uris.put( "y", "barNamespace" ); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs( uris ); // parse or create a document SAXReader reader = new SAXReader(); reader.setDocumentFactory( factory ); Document doc = reader.read( "foo.xml" ); // evaluate XPath using registered namespace prefixes // which may not appear in the document, though the URIs should String value = doc.valueOf( "/x:pizza/y:cheese/x:pepper" ); James _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ dom4j-dev mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-dev