Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the NS functions (startElementNS, writeElementNS, startAttributeN…

…S, writeAttributeNS)
  • Loading branch information...
commit 73d89590e37b4dc0577efc355ad72446bcaeb091 1 parent 1007712
quintela authored
Showing with 46 additions and 0 deletions.
  1. +46 −0 lib/xml-writer.js
View
46 lib/xml-writer.js
@@ -105,6 +105,13 @@ XMLWriter.prototype = {
return this.startElement(name).text(content).endElement();
},
+ writeElementNS : function (prefix, name, uri, content) {
+ if (!content) {
+ content = uri;
+ }
+ return this.startElementNS(prefix, name, uri).text(content).endElement();
+ },
+
startElement : function (name) {
name = strval(name);
if (!name.match(this.name_regex)) throw Error('Invalid Parameter');
@@ -124,6 +131,28 @@ XMLWriter.prototype = {
this.started_write = true;
return this;
},
+ 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 () {
if (!this.tags) return this;
@@ -147,6 +176,12 @@ XMLWriter.prototype = {
writeAttribute : function (name, content) {
return this.startAttribute(name).text(content).endAttribute();
},
+ writeAttributeNS : function (prefix, name, uri, content) {
+ if (!content) {
+ content = uri;
+ }
+ return this.startAttributeNS(prefix, name, uri).text(content).endAttribute();
+ },
startAttributes : function () {
this.attributes = 1;
@@ -172,7 +207,18 @@ XMLWriter.prototype = {
this.write(' ', name, '="');
return this;
},
+ 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 () {
if (!this.attribute) return this;
this.attribute = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.