{"name":"xpath","version":"0.0.26","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"},"typings":"./xpath.d.ts","scripts":{"test":"nodeunit test.js"},"repository":{"type":"git","url":"git+https://github.com/goto100/xpath.git"},"main":"./xpath.js","keywords":["xpath","xml"],"license":"CC-BY-SA-2.0","gitHead":"2933bb9a5208d07d6d0ac1a7eb5ecdda1329fb28","bugs":{"url":"https://github.com/goto100/xpath/issues"},"homepage":"https://github.com/goto100/xpath#readme","_id":"xpath@0.0.26","_npmVersion":"5.0.3","_nodeVersion":"8.9.1","_npmUser":{"name":"jlrishe","email":"jrishe@gmail.com"},"dist":{"integrity":"sha512-cn58wPnkUO7woqCLXlg9xeUMsPjMF7ZJ2gExwZ2F0IXkFAkL+6cyMdFUXJkld7Quw4k1y8QY9wlI3lMNNQkroQ==","shasum":"44490ef423bf28a1326d3eff325370651a8f15c0","tarball":"http://registry-npm.ywwl.com/xpath/download/xpath-0.0.26.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICTDCYm/oGMpzZAkxWZeZkrujGJceLRVuS157Sc9xiC1AiByUMxsJX5v8o9SmwlCCdyKG2nNgH1URhjET1+JQsr2Qw=="}],"size":36712,"noattachment":false,"key":"/xpath/-/xpath-0.0.26.tgz"},"maintainers":[{"name":"goto100","email":"goto100@gmail.com"},{"name":"jlrishe","email":"jrishe@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/xpath-0.0.26.tgz_1511585825893_0.23604639084078372"},"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":1511585825981,"_cnpm_publish_time":1511585825981,"dist-tags":{"latest":"0.0.36"}}