views:

83

answers:

1

I have a code like

res = doc.evalute(xpathExpr,doc,
                  function(prefix) {return namespaces[prefix] || null;},
                  XPathResult.ANY_TYPE,null );

Here doc is DOM document node

When i run for loop like this

for(i in doc) alert(i);

it gives evaluate method

but when i tried to use this method on dom node it giving me error like

xpathResult not defined...

i'm working in android browser

thanks in advance....

+2  A: 
XPathResult.ANY_TYPE

It's not guaranteed that the DOM Level 3 XPath XPathResult interface will actually be represented as a window member called XPathResult. In fact none of the DOM interfaces are specified to be reflected as constructor-functions in window. In most non-IE browsers, many of them are. But Android's browser doesn't seem to support evaluate on an HTMLDocument; I guess that's why it doesn't also provide XPathResult.

So if you want to get a static member like ANY_TYPE the only reliable way to do it is to have an instance of that class already, and access .ANY_TYPE from that. Since you don't have an XPathResult at this point, you're probably best off just saying 0.

bobince
thanks man for your reply.....But what's the point of giving evalute method support when it's return type object is not there....it's something like one function returning int and int is not defined ....secondlyif xpathResult is not defined and selectnode is also not there....how come i use xpath query in the android browser...
R_Dhorawat
Again, you should not be using `XPathResult` directly in *any* web browser. It is only a side-effect that it is present as a global variable in some browsers. Like trying to fetch `Node.ELEMENT_NODE` (which won't work in IE); there is no standard that says `window.XPathResult` should exist at all.
bobince
got your point now...one last help...can you tell me how to use xpath query in android browser.i have a Document dom node xpath expression,i have to return the list of node satisfying the xpth in xml doc.
R_Dhorawat
OK, I've just loaded the emulator to check, and it seems that unlike full-blown Chrome, the Android Browser does not support DOM Level 3 XPath on either XML or HTML documents. I don't get `evaluate` listed in `for(i in doc) alert(i);` at all.
bobince
oh sorry i checked myself.... there is no evaluate method i must have seen in chrome or firefox....thanks very much for your help....is there any way to handle these thing bcz i have to use xpath ....at any cost... means... my app needs that...is there any other way... like i can call java from javascript and do the stuff releted to xpath as backgroud process using java...if you know let me know.... thanks...
R_Dhorawat
Possibilities: http://coderepos.org/share/wiki/JavaScript-XPath http://llamalab.com/js/xpath/ http://goog-ajaxslt.sourceforge.net/ http://mcc.id.au/xpathjs
bobince
thanks man..realy appreciate your help....
R_Dhorawat