{"name":"xpath","version":"0.0.23","description":"DOM 3 Xpath implemention and helper for node.js.","engines":{"node":">=0.6.0"},"author":{"name":"Cameron McCormac"},"contributors":[{"name":"goto100"},{"name":"James Rishe"}],"dependencies":{},"devDependencies":{"nodeunit":">=0.6.4","xmldom":"^0.1.19"},"scripts":{"test":"nodeunit test.js"},"repository":{"type":"git","url":"https://github.com/goto100/xpath.git"},"main":"./xpath.js","keywords":["xpath","xml"],"license":"Creative Commons","gitHead":"8f93951c2aae50452c7049914972943be25beaf5","bugs":{"url":"https://github.com/goto100/xpath/issues"},"homepage":"https://github.com/goto100/xpath","_id":"xpath@0.0.23","_shasum":"f5e8fdc6bdc7e72885b3234f40cba2669580aafa","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"jlrishe","email":"jrishe@gmail.com"},"dist":{"shasum":"f5e8fdc6bdc7e72885b3234f40cba2669580aafa","tarball":"http://registry-npm.ywwl.com/xpath/download/xpath-0.0.23.tgz","integrity":"sha512-WHBD7+PebdFl+vGmhl/TnFLHDCTytivkerph52SF+2IUtil+lbOEK0BHHAoL+z4JOHIaF5R7Dh9VgrpnzVOFRA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDOJwYllH03jyx86rZLLFCkyMtqaM5cf/rvB6xqb6KUFwIhAL9ajX1NFCXCJDDgHRKv/Jb4JZmCADi6G6JZPsp7pkFY"}],"size":29395,"noattachment":false,"key":"/xpath/-/xpath-0.0.23.tgz"},"maintainers":[{"name":"goto100","email":"goto100@gmail.com"},{"name":"jlrishe","email":"jrishe@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/xpath-0.0.23.tgz_1460216519802_0.9233638201840222"},"directories":{},"readme":"## xpath\r\nDOM 3 XPath 1.0 implemention and helper for JavaScript, with node.js support.\r\n\r\nOriginally written by Cameron McCormack ([blog](http://mcc.id.au/xpathjs)).\r\n\r\nAdditional contributions from  \r\nYaron Naveh ([blog](http://webservices20.blogspot.com/))  \r\ngoto100  \r\nThomas Weinert  \r\nJimmy Rishe  \r\nand [others](https://github.com/goto100/xpath/graphs/contributors)\r\n\r\n## Install\r\nInstall with [npm](http://github.com/isaacs/npm):\r\n\r\n    npm install xpath\r\n\r\nxpath is xml engine agnostic but we recommend [xmldom](https://github.com/xmldom/xmldom):\r\n\r\n    npm install @xmldom/xmldom\r\n\r\n## API Documentation\r\n\r\nCan be found [here](https://github.com/goto100/xpath/blob/master/docs/xpath%20methods.md). See below for example usage.\r\n\r\n## Your first xpath:\r\n`````javascript\r\nvar xpath = require('xpath');\r\nvar dom = require('@xmldom/xmldom').DOMParser;\r\n\r\nvar xml = \"<book><title>Harry Potter</title></book>\";\r\nvar doc = new dom().parseFromString(xml, 'text/xml');\r\nvar nodes = xpath.select(\"//title\", doc);\r\n\r\nconsole.log(nodes[0].localName + \": \" + nodes[0].firstChild.data);\r\nconsole.log(\"Node: \" + nodes[0].toString());\r\n`````\r\n➡\r\n\r\n    title: Harry Potter\r\n    Node: <title>Harry Potter</title>\r\n\r\n### Alternatively\r\n\r\nUsing the same interface you have on modern browsers ([MDN])\r\n\r\n`````javascript\r\nvar node = null;\r\nvar xml = \"<book author='J. K. Rowling'><title>Harry Potter</title></book>\";\r\nvar doc = new dom().parseFromString(xml, 'text/xml');\r\nvar result = xpath.evaluate(\r\n    \"/book/title\",            // xpathExpression\r\n    doc,                        // contextNode\r\n    null,                       // namespaceResolver\r\n    xpath.XPathResult.ANY_TYPE, // resultType\r\n    null                        // result\r\n);\r\n\r\nnode = result.iterateNext();\r\nwhile (node) {\r\n    console.log(node.localName + \": \" + node.firstChild.data);\r\n    console.log(\"Node: \" + node.toString());\r\n\r\n    node = result.iterateNext();\r\n}\r\n`````\r\n➡\r\n\r\n    title: Harry Potter\r\n    Node: <title>Harry Potter</title>\r\n\r\n## Evaluate string values directly:\r\n`````javascript\r\nvar xml = \"<book><title>Harry Potter</title></book>\";\r\nvar doc = new dom().parseFromString(xml, 'text/xml');\r\nvar title = xpath.select(\"string(//title)\", doc);\r\n\r\nconsole.log(title);\r\n`````\r\n➡\r\n\r\n    Harry Potter\r\n\r\n## Namespaces\r\n`````javascript\r\nvar xml = \"<book><title xmlns='myns'>Harry Potter</title></book>\";\r\nvar doc = new dom().parseFromString(xml, 'text/xml');\r\nvar node = xpath.select(\"//*[local-name(.)='title' and namespace-uri(.)='myns']\", doc)[0];\r\n\r\nconsole.log(node.namespaceURI);\r\n`````\r\n➡\r\n\r\n    myns\r\n\r\n## Namespaces with easy mappings\r\n`````javascript\r\nvar xml = \"<book xmlns:bookml='http://example.com/book'><bookml:title>Harry Potter</bookml:title></book>\"\r\nvar select = xpath.useNamespaces({\"bookml\": \"http://example.com/book\"});\r\n\r\nconsole.log(select('//bookml:title/text()', doc)[0].nodeValue);\r\n`````\r\n➡\r\n\r\n    Harry Potter\r\n\r\n## Default namespace with mapping\r\n`````javascript\r\nvar xml = \"<book xmlns='http://example.com/book'><title>Harry Potter</title></book>\"\r\nvar select = xpath.useNamespaces({\"bookml\": \"http://example.com/book\"});\r\n\r\nconsole.log(select('//bookml:title/text()', doc)[0].nodeValue);\r\n`````\r\n➡\r\n\r\n    Harry Potter\r\n\r\n## Attributes\r\n`````javascript\r\nvar xml = \"<book author='J. K. Rowling'><title>Harry Potter</title></book>\";\r\nvar doc = new dom().parseFromString(xml, 'text/xml');\r\nvar author = xpath.select1(\"/book/@author\", doc).value;\r\n\r\nconsole.log(author);\r\n`````\r\n➡\r\n\r\n    J. K. Rowling\r\n\r\n[MDN]: https://developer.mozilla.org/en/docs/Web/API/Document/evaluate\r\n\r\n## License\r\nMIT\r\n","publish_time":1460216521911,"_cnpm_publish_time":1460216521911,"dist-tags":{"latest":"0.0.36"}}