diff options
Diffstat (limited to 'lib/xml')
| -rw-r--r-- | lib/xml/writer.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/xml/writer.js b/lib/xml/writer.js index 66cc8de..9bf8c35 100644 --- a/lib/xml/writer.js +++ b/lib/xml/writer.js @@ -25,9 +25,10 @@ function writeString(root, namespaces) { } function mapElementName(name) { - var longFormMatch = /^\{(.*)\}(.*)$/.exec(name); + var longFormMatch = /^\{(.*)\}:(.*)$/.exec(name); if (longFormMatch) { - return uriToPrefix[longFormMatch[1]] + ":" + longFormMatch[2]; + var prefix = uriToPrefix[longFormMatch[1]]; + return prefix + (prefix === "" ? "" : ":") + longFormMatch[2]; } else { return name; } @@ -35,14 +36,15 @@ function writeString(root, namespaces) { function writeDocument(root) { var builder = xmlbuilder - .create(root.name, { + .create(mapElementName(root.name), { version: '1.0', encoding: 'UTF-8', standalone: true }); _.forEach(namespaces, function(uri, prefix) { - builder.attribute("xmlns:" + prefix, uri); + var key = "xmlns" + (prefix === "" ? "" : ":" + prefix); + builder.attribute(key, uri); }); root.children.forEach(function(child) { |
