# xml2js-xpath

> Search xml2js JSON documents with XPath query strings.

Latest version **0.13.0** (published 2022-04-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install xml2js-xpath
pnpm add xml2js-xpath
yarn add xml2js-xpath
bun add xml2js-xpath
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.13.0 |
| Published | 2022-04-25 |
| First published | 2014-10-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 46 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Dane Summers |
| Maintainers | dsummersl |
| Keywords | xml2js, xpath, search, parse |

## Links

- npm: https://www.npmjs.com/package/xml2js-xpath
- Repository: https://github.com/dsummersl/node-xml2js-xpath
- Issues: https://github.com/dsummersl/node-xml2js-xpath/issues
- npm.io page: https://npm.io/package/xml2js-xpath

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## 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

- 0.13.0 (latest) — 2022-04-25
- 0.12.0 — 2021-04-10
- 0.11.0 — 2019-11-27
- 0.10.0 — 2019-05-04
- 0.9.0 — 2018-03-05
- 0.8.0 — 2016-11-26
- 0.7.0 — 2016-07-12
- 0.6.0 — 2016-01-25
- 0.5.0 — 2015-11-18
- 0.4.4 — 2014-10-24

## README

node-xml2js-xpath
=================

A library for [node-xml2js](https://github.com/Leonidas-from-XIV/node-xml2js)
that allows querying the JSON object with XPath syntax.

[![build status](https://secure.travis-ci.org/dsummersl/node-xml2js-xpath.png)](http://travis-ci.org/dsummersl/node-xml2js-xpath)

Install
=======

Use npm:

    npm install --save xml2js xml2js-xpath

Usage
=====

To use this library, first you need to some xml2js results to parse. Example:

```javascript
var xml2js = require("xml2js");
var xpath = require("xml2js-xpath");

xml2js.parseString('<root><element id="15">target</element></root>', function(err, json) {
  // find all elements: returns xml2js JSON of the element
  var matches = xpath.find(json, "//element");

  // find the first element, and get its id:
  var matches = xpath.evalFirst(json, "//element", "id");

  // Extract text representation of XML document:
  assert xpath.jsonText(json) === 'target';
});
```

See test cases for more examples.

XPath Support
=============

This project supports a subset of the [the XPath standard](https://www.w3.org/TR/1999/REC-xpath-19991116/):

- [X] Descendent selectors (`//h`, `/parent/offspring`).
- [X] Attribute selectors (`/parent/offspring[@attribute='value']`).
- [X] Tag value selectors (`/parent[offspring='value']`).
- [X] Order predicate (`/parent/offspring[1]`)

Notable unsupported features:
- [ ] Arithmetic comparisons (`/parent/offspring[@attribute > 12.5]`)
- [ ] Boolean logic (`/parent/offspring[@attribute1 or @attribute2]`)
- [ ] Axes (`/parent/following-sibling::offspring`)
- [ ] Functions ( `last()`, `starts-with()`, `contains()`, `text()`, etc).


https://www.w3.org/TR/1999/REC-xpath-19991116

https://codebeautify.org/Xpath-Tester

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