Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Tiny and simple XML writer util for NodeJS

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 package.json
README.md

simple-xml-writer

Tiny and simple XML writer util for NodeJS

Install

npm install simple-xml-writer

Examples

var XmlWriter = require('simple-xml-writer').XmlWriter;

var data = new XmlWriter(function(el) {
    el('root', function(el, at) {
        at('xmlns:c', 'http://schemas.xmlsoap.org/wsdl/');
        el('node', function(el, at) {
            at('name', 'foo');
            at('null_attr');
            at('empty_attr', '');

            el('value', 'foo');
            el('null_node');
            el('empty_node', '');
            el('encode', 'тест ß');
            el('c:value', 'text', function(el) {
                el('encoding', 'tags:  <br />', function(el, at, text) {
                    at('quotes', '""');
                    el('dd', function(el, at, text) {
                        text('foo')
                        text('bar')
                    })
                });
            });
        });
    });
}, { addDeclaration: true });

console.log(data.toString());

Output:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:c="http://schemas.xmlsoap.org/wsdl/">
  <node name="foo" empty_attr="">
    <value>foo</value>
    <empty_node/>
    <encode>&#1090;&#1077;&#1089;&#1090; &#223;</encode>
    <c:value>
      <encoding quotes="&#34;&#34;">
        <dd>foobar</dd>
        tags:  &#60;br /&#62;
      </encoding>
      text
    </c:value>
  </node>
</root>
Something went wrong with that request. Please try again.