On Mon, 29 Apr 2002, Matt Smith wrote: > Okay I just figured out the NamespaceContext by poking around the javadocs a > bit more, but Bob beat me to a response. > > So Bob - I'm trying to read through the specs to figure out why I can't > refer to an element using the prefix. The org.w3c.dom.Element.getName() > method doesn't change when I declare a namespace; in this case, it still > returns "xs:element". The various namespaces used seem like an unfortunate > bit of extra information I'm going to have to pass around, the code I'm > trying to change just has access to an Element and an xpath (String). I hate > to sound like a 2-year-old, but why do you need to know what the prefix > refers to? Isn't the node identified by the untranslated name?
I'll answer in reverse. An xpath step is in the form of 'prefix:local-name', but when performing matching, we actually match against the URI, *not* the prefix. This is actually a feature of the XPath spec. It allows you to write XPaths without caring how someone binds the prefix/URIs in the document. While you might always use "xs:", someone else might use "cheese:", but as long as they all point to the same ns-URI, then your XPath will work on both of them. So, short answer: No, node is *not* identified by untranslated name. It's identified by namespace-URI and local name. Prefix is only used to lookup the URI, not for actual matching. As far as why it worked before you defined the namespace... When you had no 'xmlns:xs="foo"', the prefix 'xs' was effectively bound to null, since it wasn't bound to anything. Since your XPath also hadn't bound it, then (null == null) and it 'worked'. Once you defined the 'xs:' prefix to be foo, then ("foo" != null), and it ceased working. I would've thought your XML parser would've complained about a namespace prefix without a valid URI bound to it. I think Jaxen should probably be smarter with undefined prefixes, though, to catch cases like this. Instead of returning null, possibly we should throw a NoSuchPrefixException or similar from the NamespaceContext translation method. I open the floor for discussion... -bob _______________________________________________ Jaxen-interest mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jaxen-interest