xml-writer
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -108,2 +108,9 @@ | ||
writeElementNS : function (prefix, name, uri, content) { | ||
if (!content) { | ||
content = uri; | ||
} | ||
return this.startElementNS(prefix, name, uri).text(content).endElement(); | ||
}, | ||
startElement : function (name) { | ||
@@ -128,3 +135,25 @@ name = strval(name); | ||
}, | ||
startElementNS : function (prefix, name, uri) { | ||
prefix = strval(prefix); | ||
name = strval(name); | ||
if (!prefix.match(this.name_regex)) throw Error('Invalid Parameter'); | ||
if (!name.match(this.name_regex)) throw Error('Invalid Parameter'); | ||
if (this.attributes) this.endAttributes(); | ||
++this.tags; | ||
this.texts = 0; | ||
if (this.stack.length > 0) | ||
this.stack[this.stack.length-1].containsTag = true; | ||
this.stack.push({ | ||
name: prefix + ':' + name, | ||
tags: this.tags | ||
}); | ||
if (this.started_write) this.indenter(); | ||
this.write('<', prefix + ':' + name); | ||
this.startAttributes(); | ||
this.started_write = true; | ||
return this; | ||
}, | ||
endElement : function () { | ||
@@ -152,2 +181,8 @@ if (!this.tags) return this; | ||
}, | ||
writeAttributeNS : function (prefix, name, uri, content) { | ||
if (!content) { | ||
content = uri; | ||
} | ||
return this.startAttributeNS(prefix, name, uri).text(content).endAttribute(); | ||
}, | ||
@@ -178,3 +213,14 @@ startAttributes : function () { | ||
}, | ||
startAttributeNS : function (prefix, name, uri) { | ||
prefix = strval(prefix); | ||
name = strval(name); | ||
if (!prefix.match(this.name_regex)) throw Error('Invalid Parameter'); | ||
if (!name.match(this.name_regex)) throw Error('Invalid Parameter'); | ||
if (!this.attributes && !this.pi) return this; | ||
if (this.attribute) return this; | ||
this.attribute = 1; | ||
this.write(' ', prefix + ':' + name, '="'); | ||
return this; | ||
}, | ||
endAttribute : function () { | ||
@@ -181,0 +227,0 @@ if (!this.attribute) return this; |
{ | ||
"name": "xml-writer", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -41,1 +41,38 @@ var XMLWriter = require('../'); | ||
}; | ||
// With NS functions | ||
exports['t06'] = function (test) { | ||
this.xw.startElementNS('t','foo'); | ||
test.equal(this.xw.toString(), '<t:foo/>'); | ||
test.done(); | ||
}; | ||
exports['t07'] = function (test) { | ||
this.xw.startElementNS('foo','tag'); | ||
this.xw.text('fake'); | ||
test.equal(this.xw.toString(), '<foo:tag>fake</foo:tag>'); | ||
test.done(); | ||
}; | ||
exports['t08'] = function (test) { | ||
this.xw.startElementNS('foo','tag'); | ||
this.xw.writeAttributeNS('foo','att',null,'value'); | ||
this.xw.writeAttribute('att', 'value'); | ||
this.xw.text('fake'); | ||
this.xw.endElement(); | ||
test.equal(this.xw.toString(), '<foo:tag foo:att="value" att="value">fake</foo:tag>'); | ||
test.done(); | ||
}; | ||
exports['t09'] = function (test) { | ||
this.xw.startDocument('1.0'); | ||
this.xw.startElementNS('rdf','RDF').writeAttributeNS('xmlns','rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#').writeAttributeNS('xmlns','cd', 'http://www.recshop.fake/cd#'); | ||
this.xw.startElementNS('rdf','Description').writeAttributeNS('rdf','about', 'http://www.recshop.fake/cd/Empire Burlesque'); | ||
this.xw.writeElementNS('cd','artist', null, 'Bob Dylan'); | ||
this.xw.writeElementNS('cd','country',null, 'USA'); | ||
this.xw.writeElementNS('cd','company', null, 'Columbia'); | ||
this.xw.writeElementNS('cd','price', null, '10.90'); | ||
this.xw.writeElementNS('cd','year', null,'1985'); | ||
this.xw.endElement(); | ||
this.xw.endElement(); | ||
this.xw.endDocument(); | ||
test.equal(this.xw.toString(), '<?xml version="1.0"?>\n<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cd="http://www.recshop.fake/cd#"><rdf:Description rdf:about="http://www.recshop.fake/cd/Empire Burlesque"><cd:artist>Bob Dylan</cd:artist><cd:country>USA</cd:country><cd:company>Columbia</cd:company><cd:price>10.90</cd:price><cd:year>1985</cd:year></rdf:Description></rdf:RDF>'); | ||
test.done(); | ||
}; |
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
29322
749
0