Right, I know that XPath doesn't care *which* prefix that is bound to the URI I use, but, I still have to use *one* of them, and not leave it off, even if it is in the default.
That is, if I'm reading documents of the form //?:a/?:b/?:c, and I know that ? is bound to http://x.y.z, but I _don't_ know for sure what the prefix will be, what is the best way to select Node z given a document object? What I have been doing is > | private Map uris = new HashMap(); > | uris.put("m",NAMESPACE); > | org.dom4j.XPath xpath = doc.createXPath("//m:what/m:ever"); > | xpath.setNamespaceURIs(uris); > | org.dom4j.Node node = xpathSel.selectSingleNode(doc); What I really want is something like: doc.selectSingleNode("//my:a/my:b/my:c","my","http://x.y.z"); I think... -Tom On Fri, 1 Nov 2002, Jan Dvorak wrote: > Date: Fri, 1 Nov 2002 09:13:43 +0100 > From: Jan Dvorak <[EMAIL PROTECTED]> > To: Tom Oehser <[EMAIL PROTECTED]>, [EMAIL PROTECTED] > Subject: Re: [dom4j-dev] selecting nodes when URI is known but prefix is > not > > Hi, > > XPath matching doesn't care about prefices in the instance document searched. > Although possible, it's by no means straightforward to write an XPath that > matches a particular prefix. > > Beware: The prefix you use in writing your XPath expressions has no > relationship whatsoever to the prefix of the node in the instance document. > > What counts in the matching are the URIs these prefices are bound to, > plus the local names, of course. These two things equal in the XPath > expression and in a node in the instance document, the node is matched. > > You could well have the default prefix in the instance document, > while in XPath you have to use an explicit prefix, should the nodes be > namespace-qualified. The prefices can differ. > > Example: The XPath expression > //x:stuff where prefix x is bound to 'urn:xmlns:com.example.stuff-1.0' > will match the following elements: > <x:stuff xmlns:x="urn:xmlns:com.example.stuff-1.0"/> > <y:stuff xmlns:y="urn:xmlns:com.example.stuff-1.0"/> > <my-weird-prefix:stuff > xmlns:my-weird-prefix="urn:xmlns:com.example.stuff-1.0"/> > <stuff xmlns="urn:xmlns:com.example.stuff-1.0"/> > > > Jan Dvorak > MathAn Praha, Ltd. > > > | Hi, > | > | I find myself doing things like: > | > | private Map uris = new HashMap(); > | uris.put("m",NAMESPACE); > | org.dom4j.XPath xpath = doc.createXPath("//m:what/m:ever"); > | xpath.setNamespaceURIs(uris); > | org.dom4j.Node node = xpathSel.selectSingleNode(doc); > | > | Instead of > | > | doc.selectSingleNode("//?:what/?:ever"); > | > | Because I know the namespace URI but not the prefix (which could be the > | default prefix). > | > | Is there an easier way to select a node using an xpath when I don't know > | the prefix? > | > | -Tom > > > > ------------------------------------------------------- > This sf.net email is sponsored by: See the NEW Palm > Tungsten T handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en > _______________________________________________ > dom4j-dev mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/dom4j-dev > ------------------------------------------------------- This sf.net email is sponsored by: See the NEW Palm Tungsten T handheld. Power & Color in a compact size! http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en _______________________________________________ dom4j-dev mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-dev