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

opixml

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opixml

Opinionated XML generator and parser

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
79
increased by51.92%
Maintainers
1
Weekly downloads
 
Created
Source

OpiXML

Opinionated XML generator and parser.

Build Status Coverage Status

Installation

npm i opixml --save

Description

Under the hood it's built on top of xml2js and js2xmlparser, but has unified interface and certain rules of mapping JS to XML and vice versa. You can pass options object for each library in appropriate method as second argument.

Mapping rules:

  • everything that is scalar is interperted as attribute
  • everything that is non-scalar is interpreted as node
  • with only one exception: if something is an object with one and only one scalar property _, then it will be treated as a value-node (see example)

Example

var obj = { 
	root: { 
		attr: '10', 
		subnode: { attr: 'foo' },
		othernode: { _: 'value' },
		container: {
			item: [
				{ one: { _: '1' } },
				{ two: { value: '2' } }
			]
		},
		container2: {
			item: [
				{ _: 1 },
				{ _: 2 }
			]
		}
	}
};
opixml.toXml(obj).then(console.log);
<root attr="10">
	<subnode attr="foo"/>
	<othernode>value</othernode>
	<container>
		<item>
			<one>1</one>
		</item>
		<item>
			<two value="2"/>
		</item>
	</container>
	<container2>
		<item>1</item>
		<item>2</item>
	</container2>
</root>
opixml.fromXml(xml).then(console.log); // you'd see obj deserialized from XML

License

MIT

Keywords

FAQs

Package last updated on 23 Aug 2016

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