views:

378

answers:

1

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
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];
Have you tried using `snapshotLength`, rather than xpath's `count`? `document.evaluate("//form", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength`
kangax