rexml
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.
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"
}
]
(c) Art Deco 2018