{"name":"xpath","version":"0.0.7","description":"DOM 3 Xpath implemention and helper for node.js.","engines":{"node":">=0.6.0"},"author":{"name":"goto100"},"dependencies":{},"devDependencies":{"nodeunit":">=0.6.4"},"repository":{"type":"git","url":"https://github.com/goto100/xpath.git"},"main":"./xpath.js","keywords":["xpath","xml"],"licenses":[{"type":"MIT License","url":"http://www.opensource.org/licenses/mit-license.php"}],"bugs":{"url":"https://github.com/goto100/xpath/issues"},"homepage":"https://github.com/goto100/xpath","_id":"xpath@0.0.7","dist":{"shasum":"2189ab236ed32d3d2cd1cadd85991d91c135b720","tarball":"http://registry-npm.ywwl.com/xpath/download/xpath-0.0.7.tgz","integrity":"sha512-wRXmsfZWSMAPpbvNT42NF6gnQsouCzHZlZikbo0V2bgQsrUm/rhPVeQphsywyOLr8xBA2PuC8VIw0A6hQMHN+g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICFCDpDCrsIouysqcGCH/wx+FTaEw7N2UE+rnK3eH53zAiEAplvlM/Bvs0s6INU1MG1U8eaMCn0sTSUKuA8b1TnX380="}],"size":22343,"noattachment":false,"key":"/xpath/-/xpath-0.0.7.tgz"},"_from":".","_npmVersion":"1.3.14","_npmUser":{"name":"goto100","email":"goto100@gmail.com"},"maintainers":[{"name":"goto100","email":"goto100@gmail.com"}],"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":1404787223496,"_cnpm_publish_time":1404787223496,"dist-tags":{"latest":"0.0.36"}}