I'm stumbled across this in my own work.

mortee says:

        The docs for XML::XPath.find suggest that if I omit the namespace
        specification, then "matching nodes from any namespace will be
included".

and it doesn't.

I'd argue this is a doc error.

Even if one thought this was a good idea, matching any namespace, under the
rubric "make simple things easy", I don't think you're ever going to get
libxml to do it. Proper namespace handling is too ingrained.

I stumbled upon code that tried to hack the xpath expression to handle
default namespaces. Creepy code.

There's really no safe solution since the same prefix can mean different
things at different points in a doc.

The "best" solution is probably to remove the namespace from the root
element (and the doctype, if necessary, I guess). But that won't match all
default namespaces: you can always write

<a xmlns="http://a";>
  <b xmlns="http://b";>
    <a/>
  </b>
</a>

and removing the top level ns isn't going to make //a match both <a> nodes.

If you really want to do that, you probably need to parse the doc, walk it,
writing out nodes w/o the namespace, and then reparse it.

_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to