|
Hi Guys
One other option is to explicity setup an
org.jaxen.NamespaceContext object with one or more namespace prefixes matched to
the namespace URIs you need which can then be used in an XPath.
I'm thinking of adding something like the following
to the XPath interface (along with maybe similar changes in Jaxen)
Document doc = ..;
// create the XPath with our namespace
prefixes
XPath xpath = doc.createXPath(
"/foo:aaa/foo:bbb/foo:xxx" );
// map the prefixes to the URIs we
want
xpath.addNamespace( "foo", "http://www.example.org/my/"
);
// now lets use it
List list = xpath.selectNodes( doc );
A word of warning though - namespaces seem to be an
area of much confusion - but the namespace prefixes that are mapped to URIs
inside an XPath expressoin (such as the above xpath object) are totally
independent of the prefixes used in the source document. To put that another
way, it doesn't matter what prefixes you choose to use in your XPath
expressions, only what URIs they map to and the namespace URIs that are in the
source document.
James
|
Title: RE: [dom4j-user] simplest way to use namespaces URI in xpath in dom4j?
- [dom4j-user] simplest way to use namespaces U... Martijn Koster
- RE: [dom4j-user] simplest way to use nam... Steen Lehmann - SilverStream
- RE: [dom4j-user] simplest way to use nam... James Strachan
- RE: [dom4j-user] simplest way to use nam... Steen Lehmann - SilverStream
- Re: [dom4j-user] simplest way to use nam... James Strachan
