does javascript on iphone mobile safari support xpath? I am using libxml2 to parse xhtml files in objective-c, but want to be able to change my parsing logic on the fly. Was considering using UIWebview's stringByEvaluatingJavaScriptFromString: method.
A:
I see that version 3.0 has document.evaluate
https://developer.mozilla.org/en/DOM/document.evaluate That's all you should need for XPATH evaluation.
kangax
2009-08-27 02:35:04
document.evaluate is not working in Simulator 3.0 or Simulator 3.1.I'm running the following inside webViewDidFinishLoad, where the page that was loaded has 2 <form> elements, and the result of the evaluation is zero.scriptCode = @"document.evaluate(\"count(//form)\", document, null, XPathResult.STRING_TYPE, null).stringValue;"; result = [thewebView stringByEvaluatingJavaScriptFromString:scriptCode];
2009-09-09 09:22:54
Have you tried using `snapshotLength`, rather than xpath's `count`? `document.evaluate("//form", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength`
kangax
2009-09-09 14:33:06