Re: [xml] XPath question



Igor Zlatkovic wrote:
On 04/08/04 19:26, Jesse Pelton wrote:

I think the operative thing here is, "Assuming foo is mapped to your
namespace name in the XPath context."  I probably should have mentioned
in my posting that I came up with my expression to deal with
environments where there was no mechanism to establish such mappings
other than by including a namespace prefix in the instance document.  As
far as I can see, XPath 1.0 does not specify such a mechanism, but
libxml does, of course.  So, my posting was not completely relevant to
this list.  I was excited to find a solution (even if inefficient) to a
real problem that I had; I hope I can be forgiven for choosing the wrong
forum to share it!


Peace. There is a misunderstanding here. You think you have solved the problem, I think you just hid it with another, ending up with two.

Hmm, I'm thinking that I disagree with everyone here! :>
Daniel has pointed out that you can --- and should --- bind a namespace
prefix for XPath, but that how that is done is outside of the XPath
spec itself.

OTOH, I would mildly quibble that the notion that
*[namespace-uri() == 'bar' and local-name() == 'a']
is _inherently_ inefficient; it is logically equivalent to foo:a
(w/ appropriate bindings). HOWEVER, doing it efficiently requires
query optimization --- which shouldn't be assumed, or even expected.
... and I'm not suggesting libxml should do it! :>
So, never mind.

Whoever produces XML of the sort

  ...
  <a xmlns="foo">
    <n/>
  </a>
  <a xmlns="bar">
    <n/>
  </a>
  ...

should be made aware of the fact that the thing cannot be processed efficiently. Using namespace prefixes solves this without changing anything about the data the document contains.

Why in the world should one be more efficient than the other?
[Inherently? Or do you refer to one specific processor? libxml2?]
Ultimately, the XPath processor has to look for pairs of URI + localname.
The URI is what's important; the prefix used in the document (if any) can be
completely different from the prefix used in the XPath context.

Sure, it is customer's document, you have no control of it. If so, you are giving the customer an ill service if you let her get away with it. I cannot speak for everyone, but I'll appreciate an advice about my wrongdoing far more than silence and an inneficient workaround.

Well, even if it's my document, it sometimes isn't so easy to control
how the namespaces get serialized.... but that's another thread! :>

Peace now?

All peace on this end !

Ciao,
Igor
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml




--
--
bruce miller nist gov
http://math.nist.gov/~BMiller/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]