From: Keith B. <KSB...@lb...> - 2003-10-17 09:17:51
|
Well, I'm having trouble finding an introductory reference on xpath that includes namespaces (I generally try to avoid starting with the spec but it appears I don't have much of a choice here). But in the meantime... Shaun McCance wrote: > The XPath expression isn't part of the XML document, so the namespace > declarations in the XML document are irrelevant to the XPath expression. > The prefix-namespace association has to be given to the XPath processor > for a namespace prefix in an XPath to mean anything. Seems to me that the same be said about any element or attribute name. > You might wonder why an XPath processor can't just look at the prefixes > used in the XML file and use the same ones. *Exactly* what I'm wondering! > Here's an example: > > <foo:foo xmlns:foo="http://example.com/foo"> > <foo:bar/> > <foo:bar xmlns:foo="http://example.com/foobar"/> > </foo:foo> > > What would the XPath expression //foo:bar select? I guess I'd expect both foo:bar elements: <foo:bar/> <foo:bar xmlns:foo="http://example.com/foobar"/> Which means that I'm assuming the absence of a namespace specification means 'any namespace'. Bad assumption on my part apparently... :) So is it possible to provide these prefix-namespace associations in the xpath expression itself? And not pass it in via (what appears to be the out-of-band method of) the XPath element? For example, rather than: <XPath xmlns:foo="http://example.com/foo"> //foo:bar </XPath> something like: <XPath> //foo:bar[ns::xmlns:foo="http://example.com/foo"> </XPath> even though I know that's not the proper syntax. (I ask because I'm working with another xpath implementation (in python) and using xmlstar as a reference.) Thanks so much for your time. ksb |