javascript - js plugin to draw html dom tree from str and calculate xpath -
i want make code take html str
$str = '<!doctype html> <html> <head> </head> <body> <div> <div> <strong></strong> </div> </div> </body> </html>';
and assign needed function
<script type="text/javascript"> draw_dome_with_xpath_cal(<?php echo $str; ?>) </script>
from php, ok? , js make dom clickbale, , when click on element calcaulate firfox xpath function example
<script type="text/javascript"> /** * gets xpath element describes hierarchical location. */ var getelementxpath = function(element) { if (element && element.id) return '//*[@id="' + element.id + '"]'; else return getelementtreexpath(element); }; var getelementtreexpath = function(element) { var paths = []; // use nodename (instead of localname) namespace prefix included (if any). (; element && element.nodetype == 1; element = element.parentnode) { var index = 0; // test element.id if (element && element.id) { paths.splice(0, 0, '/*[@id="' + element.id + '"]'); break; } (var sibling = element.previoussibling; sibling; sibling = sibling.previoussibling) { // ignore document type declaration. if (sibling.nodetype == node.document_type_node) continue; if (sibling.nodename == element.nodename) ++index; } var tagname = element.nodename.tolowercase(); var pathindex = (index ? "[" + (index+1) + "]" : ""); paths.splice(0, 0, tagname + pathindex); } return paths.length ? "/" + paths.join("/") : null; }; </script>
Comments
Post a Comment