{"_id":"xpath@0.0.36","bugs":{"url":"https://github.com/goto100/xpath/issues"},"dist":{"shasum":"1dff2140de4a4a772f3c583b7f719f996aa3ed50","tarball":"http://registry-npm.ywwl.com/xpath/download/xpath-0.0.36.tgz","fileCount":5,"integrity":"sha512-HuqAnJx5YJoDeLub7hhcNoiRvnqqrgoSsI4kLrOtv6XkaUI0zY9ylL4+ULozB35JT1SVMfdexsMqRbTp7bkFGQ==","signatures":[{"sig":"MEYCIQDsHbkWCn2yGSasF3stQPXCZUMrNHnf+VcCP0/wtx9A+AIhALYu3q3xG8be1VoUBE/ckLIED2b465rNj4yAI11gIOYu","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIF9I4qmOgX1RKxU1j6UuX4coWw7fXvbp9+xqq3cnYN/yAiARTB8mWOt5hIrG7q0hoEF8qflCkuVK06PAZttoF20FIQ=="}],"unpackedSize":185404,"size":30640,"noattachment":false,"key":"/xpath/-/xpath-0.0.36.tgz"},"main":"xpath.js","name":"xpath","author":{"name":"Cameron McCormack"},"engines":{"node":">=0.6.0"},"gitHead":"8f38c263f34bbe5c35b49a2339e23113aa85524b","license":"MIT","scripts":{"test":"mocha","validate":"es-check es5 xpath.js"},"typings":"./xpath.d.ts","version":"0.0.36","_npmUser":{"name":"jlrishe","email":"jrishe@gmail.com"},"homepage":"https://github.com/goto100/xpath#readme","keywords":["xpath","xml"],"repository":{"url":"git+https://github.com/goto100/xpath.git","type":"git"},"_npmVersion":"10.9.9","description":"DOM 3 XPath implemention and helper for node.js and the web","directories":{},"maintainers":[{"name":"goto100","email":"goto100@gmail.com"},{"name":"jlrishe","email":"jrishe@gmail.com"}],"_nodeVersion":"22.23.4","contributors":[{"name":"goto100"},{"name":"James Rishe"}],"_hasShrinkwrap":false,"devDependencies":{"mocha":"^9.0.2","es-check":"^7.1.1","func-xml":"^0.0.10","@xmldom/xmldom":"^0.8.9"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/xpath_0.0.36_1793169699441_0.0096621983159354"},"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":1793169699536,"_cnpm_publish_time":1793169699536,"dist-tags":{"latest":"0.0.36"}}