Comparing version 0.6.0 to 0.6.1
18
index.js
@@ -5,3 +5,3 @@ var sax = require("sax"); | ||
scope = scope || 0; | ||
var result = prefix(scope) + '<' + node.name; | ||
var result = '<' + node.name; | ||
@@ -15,8 +15,8 @@ // Attributes | ||
if(node.children.length > 0) { | ||
result += '>\n'; | ||
result += '>'; | ||
node.children.forEach(function(c) { | ||
if (typeof c === 'string') result += c; | ||
else result += serializeNode(scope + 1,c) + "\n"; | ||
else result += serializeNode(scope + 1,c); | ||
}, this); | ||
result += prefix(scope) + '</'+node.name+'>'; | ||
result += '</'+node.name+'>'; | ||
} | ||
@@ -73,3 +73,3 @@ else{ | ||
{ | ||
this.addNamespace("", value); | ||
this.setNamespace(value); | ||
} | ||
@@ -109,5 +109,11 @@ | ||
setNamespace(url) { | ||
this.addNamespace(null, url); | ||
} | ||
addNamespace(prefix, url) { | ||
this.namespaces.push({ prefix: prefix, value: url }); | ||
this.attributes["xmlns:"+prefix] = url; | ||
var attname = "xmlns"; | ||
if(prefix) attname += ":" + prefix; | ||
this.attributes[attname] = url; | ||
} | ||
@@ -114,0 +120,0 @@ |
{ | ||
"name": "xmlobject", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Convert javascript objects to and from xml strings.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,2 +28,6 @@ # xmlobject | ||
/* -> | ||
{"name":"a","attributes":{"xmlns:":"http://www.example.com/xml/default","xmlns":"http://www.example.com/xml/default","xmlns:test":"http://www.example.com/xml/test","b":"c","d":"e"},"namespaces":[{"prefix":"","value":"http://www.example.com/xml/default"},{"prefix":"test","value":"http://www.example.com/xml/test"}],"children":[{"name":"test:f","attributes":{"test:i":"j"},"namespaces":[],"children":["g",{"name":"h","attributes":{},"namespaces":[],"children":[]}]}]} | ||
*/ | ||
}); | ||
@@ -36,6 +40,7 @@ | ||
a.setAttribute("d","e"); | ||
a.addNamespace("test", ns) | ||
a.setNamespace(defaultns); | ||
a.addNamespace("test", ns); | ||
var f = a.createChild(ns,"f"); | ||
f.setAttribute(ns,"i","j") | ||
f.setAttribute(ns,"i","j"); | ||
f.addChild("g"); | ||
@@ -46,2 +51,6 @@ f.createChild("h"); | ||
console.log(r); | ||
/* -> | ||
<a b="c" d="e" xmlns="http://www.example.com/xml/default" xmlns:test="http://www.example.com/xml/test"><test:f test:i="j">g<h /></test:f></a> | ||
*/ | ||
}); | ||
@@ -48,0 +57,0 @@ ``` |
14
test.js
var XML = require('.'); | ||
var assert = require('assert'); | ||
@@ -16,2 +15,6 @@ // Deserialize from xml | ||
/* -> | ||
{"name":"a","attributes":{"xmlns:":"http://www.example.com/xml/default","xmlns":"http://www.example.com/xml/default","xmlns:test":"http://www.example.com/xml/test","b":"c","d":"e"},"namespaces":[{"prefix":"","value":"http://www.example.com/xml/default"},{"prefix":"test","value":"http://www.example.com/xml/test"}],"children":[{"name":"test:f","attributes":{"test:i":"j"},"namespaces":[],"children":["g",{"name":"h","attributes":{},"namespaces":[],"children":[]}]}]} | ||
*/ | ||
}); | ||
@@ -24,6 +27,7 @@ | ||
a.setAttribute("d","e"); | ||
a.addNamespace("test", ns) | ||
a.setNamespace(defaultns); | ||
a.addNamespace("test", ns); | ||
var f = a.createChild(ns,"f"); | ||
f.setAttribute(ns,"i","j") | ||
f.setAttribute(ns,"i","j"); | ||
f.addChild("g"); | ||
@@ -34,2 +38,6 @@ f.createChild("h"); | ||
console.log(r); | ||
/* -> | ||
<a b="c" d="e" xmlns="http://www.example.com/xml/default" xmlns:test="http://www.example.com/xml/test"><test:f test:i="j">g<h /></test:f></a> | ||
*/ | ||
}); |
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
10889
208
62