Advertisement
rplantiko

Evaluate XPath in a Browser

Sep 28th, 2013
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Evaluating an XPath Expression in the browser (tested in Firefox)
  2. // For Cross-Browser stuff, check the small library Sarissa.js (http://dev.abiss.gr/sarissa/)
  3. var doc = new DOMParser().parseFromString("<root><a>A<b/>A<c/></a><b/></root>", "text/xml")
  4. var iterator = doc.evaluate('//b', doc.documentElement, null,XPathResult.ANY_TYPE, null );
  5. console.log(iterator)
  6. try {
  7.   var thisNode = iterator.iterateNext();
  8.  
  9.   while (thisNode) {
  10.     console.log( thisNode );
  11.     thisNode = iterator.iterateNext();
  12.   }
  13. }
  14. catch (e) {
  15.   dump( 'Error: Document tree modified during iteration ' + e );
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement