xpath and thunderbird

[email protected] Wed, 14 Feb 2007 11:26:42 +1100
Newsgroups gmane.comp.mozilla.devel.xml
Message-ID <[email protected]>
Hi -

I'm trying to do is use xpath from within thunderbird.  What I'm
finding is that the document.evaluate() method doesn't exist.

I posted a similar message to dev-apps-thunderbird yesterday, but I've
since put together some test cases (below) and also realised that this
list is probably more appropriate anyway.

Unless I'm doing something silly, I wonder whether there might be a
configure/build-time bug, as the symptoms are similar to this thread
from 2005 which reported a similar problem with sunbird:
http://groups.google.com/group/netscape.public.mozilla.xml/browse_thread/thread/7d736646ffa76d69
In that case, the resulting bug has since been fixed:
https://bugzilla.mozilla.org/show_bug.cgi?id=306701

Anyway, if someone can suggest a workaround I'd be grateful, otherwise
I'll have to rewrite my xpath code (developed under xulrunner) to use
getElementsByTagNameNS.

Thanks -

Leni.

Here are some test cases which suggest that xpath isn't available from
within thunderbird 1.5.x or 2.0 beta.  The test case behaviour doesn't
change whether the code is run from within an extension or within a
Javascript Shell - I'm using the one bundled with:
ted.mielczarek.org/code/mozilla/extensiondev/

Test Case One - xpath
=====================
   var parser = new DOMParser();
   var xmldoc = parser.parseFromString("<hello/>", "text/xml");
   dump("xmldoc.evaluate() is " + typeof(xmldoc.evaluate) + "\n");
   // prints "function" when run from within mozilla but
   // prints "undefined" when run from within thunderbird
   // 1.5.x or 2.0 beta.

Test Case Two - xpointer xpath() scheme
=======================================
  // test the xpointer xpath1() scheme
  // based on the example from http://www.w3.org/TR/xptr-xmlns/
  //
  var parser = new DOMParser();
  var xmldoc = parser.parseFromString("<customer
    xmlns='http://example.org/customer'><name
    xmlns='http://example.org/personal-info'>
    John Doe</name></customer>", "text/xml");
  var result =
   xmldoc.evaluateXPointer("xmlns(c=http://example.org/customer)
   xmlns(p=http://example.org/personal-info)
   xpath1(/c:customer/p:name)");
  print(result);
  // prints [object XPointerResult] when run from mozilla
  // prints null                    when run from thunderbird
  // but as an aside I noticed that the element() scheme works ok
  //  in thunderbird

And this last test isn't really a test case, just a bit more
information that might point to what is going on.

Test Case Three - category manager
==================================
  var catman = Components.classes["@mozilla.org/categorymanager;1"].
     getService(Components.interfaces.nsICategoryManager);
  var item   = catman.enumerateCategory("JavaScript DOM class");
  while (item.hasMoreElements()) {
    var subitem = item.getNext();
    var tmp = subitem.
       QueryInterface(Components.interfaces.nsISupportsCString).data;
    print("\t" + tmp + "\n");
  }
  // in thunderbird 2.0 beta prints:
  //    XPointerResult
  //
  // in mozilla, prints:
  //    XPathEvaluator
  //    XPathException
  //    XPathExpression
  //    XPathNSResolver
  //    XPathResult
  //    XPointerResult
  //    XSLTProcessor