Skip to content

this renders a simple javascript object structure into xml/html. js objects are easier to modify than strings so no need to parse a whole dom to reliably add a few elements. while this could support async callbacks it doesn't. if people need it i will be happy to add support.

License

Notifications You must be signed in to change notification settings

Raigen/node-jsontoxml

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a library designed to render js objects as xml.
Its not made to parse or otherwise edit existing xml/html structures.
For that and perhaps as a compliment to this you can use jsdom for editing existing markup.

Its real easy to make xml. I made this because i wanted to abstract away the fact that antiquated external systems require post data as xml and i wanted to expose a standard js calling api like my other interfaces.
I did not want to instantiate an entire dom to perform simple updates to tags in lower level functions (like injecting api keys) when top level api call specific functions start building the xml string.

HOW TO INSTALL:

NPM:

npm install jsontoxml

Git:

git clone git://github.com/soldair/node-jsontoxml.git


HOW TO USE:

var jsonxml = require('jsonxml');
// if you "installed" with git
// var jsonxml = require(path_to_jonxml+'/jsonxml');

jsonxml.obj_to_xml({
	node:'text content',
	parent:[
		{name:'taco',text:'beef taco',children:{salsa:'hot!'}},
		{name:'taco',text:'fish taco',attrs:{mood:'sad'},children:[
			{name:'salsa',text:'mild'},
			'hi',
			{name:'salsa',text:'weak',attrs:{type:2}}
		]},
		{name:'taco',attrs:'mood="party!"'}
	],
	parent2:{
		hi:'is a nice thing to say',
		node:'i am another not special child node'
		date:function(){
			return (new Date())+'';
		}
	}
})

outputs:  // ! output is not tabbed this is an example

<node>text content</node>
<parent>
	<taco>
		beef taco
		<salsa>hot!</salsa>
	</taco>
	<taco mood='sad'>
		fish taco
		<salsa>mild</salsa>
		hi
		<salsa type="2">weak</salsa>
	</taco>
	<taco mood='party!'/>
</parent>
<parent2>
	<hi>is a nice thing to say</hi>
	<node>i am another not special child node</node>
	<date>Sun Sep 26 2010 17:27:29 GMT-0700 (PDT)</date>
</parent2>

About

this renders a simple javascript object structure into xml/html. js objects are easier to modify than strings so no need to parse a whole dom to reliably add a few elements. while this could support async callbacks it doesn't. if people need it i will be happy to add support.

Resources

License

Stars

Watchers

Forks

Packages

No packages published