4.0.5 • Published 2 years ago

xml-renderer v4.0.5

Weekly downloads
59
License
MIT
Repository
github
Last release
2 years ago

xml-renderer

Combines XML and XPath with your components and stylesheets to render whatever in React or elsewhere. Can be used for front- or back-end rendering.

Docs & demo

You can read all the documentation here, or start reading at the most probable API's:

See also;

Installation

npm i xml-renderer --save

Example

import React from 'react';
import { sync } from 'slimdom-sax-parser';

// Take the default export of `xml-renderer`
import { ReactRenderer } from 'xml-renderer';

// Instantiate a new object to contain rendering rules
const experience = new ReactRenderer();

// For text nodes you _probably_ just want to show the text content
experience.add('self::text()', ({ node }) => node.nodeValue);

// For some nodes, including the document node, you _probably_ just want to render the children
experience.add('self::node()', ({ traverse }) => traverse());

// For other nodes you may want to add a template
experience.add('self::paragraph', ({ traverse }) => <p>{traverse()}</p>);

// For some situations you may want to specify a more specific test
experience.add('self::paragraph[not(preceding-sibling::*)]', ({ traverse }) => (
	<p>
		<b>{traverse()}</b>
	</p>
));

// For some situations you may want to traverse into specific children, or add some elements of your own
experience.add('self::webpage', ({ traverse }) => (
	<div>
		<h1>My first page</h1>
		{traverse('./paragraph')}
	</div>
));

// ReactRenderer#render returns React elements, so you can use them in React like any other JS value
export default function MyXmlDocument({ xmlString }) {
	return <div className="doc-or-whatever">{xp.render(React.createElement, sync(xmlString))}</div>;
}
4.0.5

2 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

4 years ago

4.0.0-beta.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-alpha.1

4 years ago

3.0.0-alpha.0

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

6 years ago

2.0.0-rc3

6 years ago

2.0.0-rc2

6 years ago

2.0.0-rc1

6 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago