# xpathns.js

> Wrapper for xpath.js to allow namespaces in queries

Latest version **1.0.3** (published 2015-04-20) · Apache License 2.0 license · 0 weekly downloads

## Install

```sh
npm install xpathns.js
pnpm add xpathns.js
yarn add xpathns.js
bun add xpathns.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2015-04-20 |
| First published | 2015-04-20 |
| Weekly downloads | 0 |
| License | Apache License 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kieran Simpson |
| Maintainers | kierans777 |
| Keywords | xml, xpath |

## Links

- npm: https://www.npmjs.com/package/xpathns.js
- Repository: https://bitbucket.org/kierans777/xpathns.js
- Issues: https://bitbucket.org/kierans777/xpathns.js/issues
- npm.io page: https://npm.io/package/xpathns.js

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2015-04-20
- 1.0.2 — 2015-04-20
- 1.0.1 — 2015-04-20

## README

## xpathns.js
Wrapper for [xpath.js](https://www.npmjs.com/package/xpath.js) to allow namespaces in queries.

Examples in this README modified from xpath.js README.

## Install
Install with [npm](http://github.com/isaacs/npm):

    npm install xpathns.js

Install xpath.js and an XML engine (eg: [xmldom](https://github.com/jindw/xmldom)):

    npm install xpath.js xmldom


## Your first xpath with namespaces:
`````javascript
	var nsMap = {
		ns1: "urn:somenamespace"
	};
  
	var select = require("xpathns.js")(nsMap),
	    dom = require("xmldom").DOMParser;

	var xml = "<book xmlns=\"urn:somenamespace\"><title>Harry Potter</title></book>";
	var doc = new dom().parseFromString(xml);
	var nodes = select(doc, "//ns1:title");
	
	console.log(nodes[0].localName + ": " + nodes[0].firstChild.data);
	console.log("node: " + nodes[0].toString());
`````
-->

	title: Harry Potter
	node: <title>Harry Potter</title>

## Get text values directly
`````javascript 
    var xml = "<book xmlns=\"urn:somenamespace\"><title>Harry Potter</title></book>";
    var doc = new dom().parseFromString(xml);
    var title = select(doc, "//ns1:title/text()")[0].data;

    console.log(title);
`````  
-->
    
    Harry Potter
	
## Attributes
`````javascript  
    var xml = "<book xmlns=\"urn:somenamespace\" author='J. K. Rowling'><title>Harry Potter</title></book>";
    var doc = new dom().parseFromString(xml);
    var author = select(doc, "/ns1:book/@author")[0].value;
        
    console.log(author);
`````
-->
    
    J. K. Rowling

---
_Source: https://npm.io/package/xpathns.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
