Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rexml

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rexml

Simple XML parsing with a regular expression.

  • 1.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
98
decreased by-55.25%
Maintainers
1
Weekly downloads
 
Created
Source

rexml

npm version

rexml is a Node.js package for simple XML parsing with a regular expression. It's been tested to work for simple use cases.

yarn add -E rexml

Table Of Contents

API

The package is available by importing its default function:

import rexml from 'rexml'

rexml(
  tag: string,
  string: string,
): {content, props}[]

Extract tags from the XML string. The tags are returned as an array with objects containing content and props properties. The content is the inner content of the tag, and props is the attributes specified inside the tag.

/* yarn example/ */
import extractTags from 'rexml'

const xml = `
<html>
  <div id="d1"
    class="example"
    contenteditable />
  <div id="d2" class="example">Hello World</div>
</html>
`

const res = extractTags('div', xml)

console.log(JSON.stringify(res, null, 2))
[
  {
    "props": {
      "id": "d1",
      "class": "example",
      "contenteditable": true
    },
    "content": ""
  },
  {
    "props": {
      "id": "d2",
      "class": "example"
    },
    "content": "Hello World"
  }
]

extractProps(
  string: string,
  parseValue?: boolean,
): Object<string,(boolean|string|number)>

Extracts the properties from the attributes part of the tag and returns them as an object. It will parse values if not specified otherwise.

import { extractProps } from 'rexml'

const s = `id="d2"
class="example"
value="123"
parsable="true"
ignore="false"
required`

const res = extractProps(s)
console.log(JSON.stringify(res, null, 2))

// don't parse booleans and integers
const res2 = extractProps(s, false)
console.log(JSON.stringify(res2, null, 2))
{
  "id": "d2",
  "class": "example",
  "value": 123,
  "parsable": true,
  "ignore": false,
  "required": true
}
{
  "id": "d2",
  "class": "example",
  "value": "123",
  "parsable": "true",
  "ignore": "false",
  "required": true
}

Art Deco © Art Deco 2019 Tech Nation Visa Tech Nation Visa Sucks

Keywords

FAQs

Package last updated on 08 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc