# @vates/xml-rpc

> Parse and format XML-RPC messages, do not handle transport or XML

Latest version **1.0.0** (published 2024-04-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install @vates/xml-rpc
pnpm add @vates/xml-rpc
yarn add @vates/xml-rpc
bun add @vates/xml-rpc
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-04-30 |
| First published | 2024-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 987 |
| Author | Vates SAS |
| Maintainers | mlssfrncjrg, b-nollet, arnogues, florent.beauchamp, mathieura, enishowk, tgoettelmann, julien-f, marsaud, olivierlambert, pdonias |

## Links

- npm: https://www.npmjs.com/package/@vates/xml-rpc
- Repository: https://github.com/vatesfr/xen-orchestra
- Homepage: https://github.com/vatesfr/xen-orchestra/tree/master/@vates/xml-rpc
- Issues: https://github.com/vatesfr/xen-orchestra/issues
- npm.io page: https://npm.io/package/@vates/xml-rpc

## Recent versions

- 1.0.0 (latest) — 2024-04-30

## README

<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->

# @vates/xml-rpc

[![Package Version](https://badgen.net/npm/v/@vates/xml-rpc)](https://npmjs.org/package/@vates/xml-rpc) ![License](https://badgen.net/npm/license/@vates/xml-rpc) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/xml-rpc)](https://bundlephobia.com/result?p=@vates/xml-rpc) [![Node compatibility](https://badgen.net/npm/node/@vates/xml-rpc)](https://npmjs.org/package/@vates/xml-rpc)

> Parse and format XML-RPC messages, do not handle transport or XML

## Install

Installation of the [npm package](https://npmjs.org/package/@vates/xml-rpc):

```sh
npm install --save @vates/xml-rpc
```

## Usage

### Formatting

```js
import { xmlRpcFormatter } from '@vates/xml-rpc/formatter'

// There is a dedicated method per XML-RPC tag (`array`, `string`, etc.)
xmlRpcFormatter.format_methodCall({
  methodName: 'examples.getStateName',
  params: [40],
})
// → {
//   name: 'methodCall',
//   children: [
//     {
//       name: 'methodName',
//       children: [ 'examples.getStateName' ]
//     },
//     {
//       name: 'params',
//       children: [
//         {
//           name: 'param',
//           children: [ { name: 'value', children: [ '40' ] } ]
//         }
//       ]
//     }
//   ]
// }

// There is a dedicated method to format a JS value
xmlRpcFormatter.format_js(new Date(900684535000))
// → {
//   name: 'dateTime.iso8601',
//   children: [ '1998-07-17T14:08:55.000Z' ]
// }
```

Formatting XML is out of this library's scope, but you can achieve it easily with
`@vates/xml`:

```js
import { formatXml } from '@vates/xml/format'

// it can now be passed to the XML-RPC parser
const tree = xmlRpcFormatter.format_methodCall({
  methodName: 'examples.getStateName',
  params: [40],
})

// avoid any indentation or new lines as it will confuse many XML-RPC parsers.
const xml = formatXml(tree, { indent: 0 })
```

### Parsing

```js
import { xmlRpcParser } from '@vates/xml-rpc/parser'

xmlRpcParser.parse({
  name: 'methodResponse',
  children: [
    {
      name: 'params',
      children: [
        {
          name: 'param',
          children: [
            {
              name: 'value',
              children: [
                {
                  name: 'string',
                  children: ['South Dakota'],
                },
              ],
            },
          ],
        },
      ],
    },
  ],
})
// { params: [ 'South Dakota' ] }

// There is a dedicated method per XML-RPC tag (`array`, `string`, etc.)
xmlRpcParser.parse_array({
  name: 'array',
  children: [
    {
      name: 'data',
      children: [
        {
          name: 'value',
          children: [{ name: 'boolean', children: ['1'] }],
        },
        {
          name: 'value',
          children: [{ name: 'int', children: ['42'] }],
        },
      ],
    },
  ],
})
// [ true, 42 ]
```

Parsing XML is out of this library's scope, but you can achieve it easily with
`@vates/xml`:

```js
import { parseXml } from '@vates/xml/parse'

const xml = `
<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
        <value><string>South Dakota</string></value>
    </param>
  </params>
</methodResponse>
`

const tree = parseXml(xml)

// it can now be passed to the XML-RPC parser
xmlRpcParser.parse(tree)
```

## Contributions

Contributions are _very_ welcomed, either on the documentation or on
the code.

You may:

- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
  you've encountered;
- fork and create a pull request.

## License

[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)

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