Comparing version 0.0.10 to 0.0.11
//copyright Ryan Day 2010 <http://ryanday.org>, Joscha Feth 2013 <http://www.feth.com> [MIT Licensed] | ||
var element_start_char = | ||
"a-zA-Z_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FFF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD"; | ||
var element_non_start_char = "\-.0-9\u00B7\u0300-\u036F\u203F\u2040"; | ||
var element_replace = new RegExp("^([^" + element_start_char + "])|^((x|X)(m|M)(l|L))|([^" + element_start_char + element_non_start_char + "])", "g"); | ||
var process_to_xml = function(node_data,options){ | ||
@@ -11,2 +14,5 @@ | ||
var indent = options.prettyPrint ? '\n' + new Array(level).join(indent_value) : ''; | ||
if(options.removeIllegalNameCharacters) { | ||
name = name.replace(element_replace, '_'); | ||
} | ||
@@ -176,2 +182,3 @@ var node = [indent, '<',name, (attributes || '')]; | ||
.replace(/>/g, '>') | ||
.replace(/'/g, ''') | ||
.replace(/"/g, '"'); | ||
@@ -178,0 +185,0 @@ } |
{ | ||
"name": "jsontoxml", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "This is a library designed to render js objects as xml. Its not made to parse or otherwise edit existing xml/html structures.", | ||
"homepage": "http://github.com/soldair/node-jsontoxml", | ||
"homepage": "http://github.com/ken-franken/node-jsontoxml", | ||
"main": "./jsontoxml.js", | ||
@@ -7,0 +7,0 @@ "devDependencies": { |
@@ -78,2 +78,3 @@ [![Build Status](https://secure.travis-ci.org/soldair/node-jsontoxml.png)](http://travis-ci.org/soldair/node-jsontoxml) | ||
- `indent` specify what unit you would like to indent by (spaces, tabstop, nothing - pass an empty string) | ||
- `removeIllegalNameCharacters` replace illegal XML element Name characters with '_' | ||
@@ -80,0 +81,0 @@ |
41
test.js
@@ -12,2 +12,3 @@ //copyright Ryan Day 2010 <http://ryanday.org> [MIT Licensed] | ||
{name:'taco',text:'beef taco',children:{salsa:'hot!'}}, | ||
{name:'xml',text:'tag'}, | ||
{name:'taco',text:'fish taco',attrs:{mood:'sad'},children:[ | ||
@@ -28,3 +29,4 @@ {name:'salsa',text:'mild'}, | ||
var expected = '<node>text content</node>' | ||
var expected_no_element_substitution = | ||
'<node>text content</node>' | ||
+'<parent>' | ||
@@ -35,2 +37,3 @@ +'<taco>' | ||
+'</taco>' | ||
+'<xml>tag</xml>' | ||
+'<taco mood="sad">' | ||
@@ -51,2 +54,26 @@ +'fish taco' | ||
var expected_with_element_substitution = | ||
'<node>text content</node>' | ||
+'<parent>' | ||
+'<taco>' | ||
+'beef taco' | ||
+'<salsa>hot!</salsa>' | ||
+'</taco>' | ||
+'<_>tag</_>' | ||
+'<taco mood="sad">' | ||
+'fish taco' | ||
+'<salsa>mild</salsa>' | ||
+'hi' | ||
+'<salsa type="2">weak</salsa>' | ||
+'</taco>' | ||
+"<taco mood=\"party!\"/>" | ||
+'</parent>' | ||
+'<parent2>' | ||
+'<hi>this & this is a nice thing to say</hi>' | ||
+'<node>i am another not special child node</node>' | ||
+'<date>'+date+'</date>' | ||
+'<date2>'+date.toJSON()+'</date2>' | ||
+'</parent2>'; | ||
var expected = expected_no_element_substitution; | ||
var buffer = new Buffer(JSON.stringify(input)); | ||
@@ -60,7 +87,13 @@ | ||
test("creates correct object",function(t){ | ||
test("creates correct object from string",function(t){ | ||
var result = jsonxml(input,{escape:true}); | ||
t.equals(result,expected,' should have generated correct xml'); | ||
console.log(result) | ||
t.equals(result,expected,' test should have generated correct xml'); | ||
t.end() | ||
}); | ||
test("creates correct object with element fixup",function(t){ | ||
var result = jsonxml(input,{escape:true, removeIllegalNameCharacters:true}); | ||
t.equals(result,expected_with_element_substitution,' test should have generated correct xml'); | ||
t.end() | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253229
7507
98