Registry / storage / xmlify

xmlify

JSON →
library1.1.0jsnpmunverified

Converts JavaScript/JSON objects, particularly MongoDB/Mongoose documents, to XML. Version 1.1.0 (latest) as of 2014. Ignores null/undefined values and converts Date objects to ISO format. Key differentiator: uses leading underscore to denote XML attributes, wraps pluralized arrays in singular enclosing elements by default. Stable but old; no updates since 2014.

npm install xmlify
INSTALL
IMPORT
SIG · XMLIFY
X
xmlify
storagejavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import xmlify from 'xmlify'
const { xmlify } = require('xmlify')
Default export only; named import will fail.
default
const xmlify = require('xmlify')
const { default: xmlify } = require('xmlify')
CommonJS require works directly.
default
import * as xmlify from 'xmlify'
import { xmlify } from 'xmlify'
Default export, not named.

Converts a Mongoose-like document to XML with options for root element and attribute prefix.

const xmlify = require('xmlify'); const blog = { _id: '54551d0b660186630b790db0', title: 'My Blog', author: 'Me', comments: [ { body: 'Nice blog', date: new Date('2014-11-02') }, { body: 'Bit short', date: new Date('2014-11-03') } ], meta: { votes: 9, favs: 99 } }; const xml = xmlify(blog, 'blog'); console.log(xml); // <blog id="54551d0b660186630b790db0"> // <title>My Blog</title> // <author>Me</author> // <comments> // <comment> // <body>Nice blog</body> // <date>2014-11-02T00:00:00.000Z</date> // </comment> // <comment> // <body>Bit short</body> // <date>2014-11-03T00:00:00.000Z</date> // </comment> // </comments> // <meta> // <votes>9</votes> // <favs>99</favs> // </meta> // </blog>
Debug
Known issues
gotchaProperties beginning with underscore are treated as attributes by default — if you have properties with leading underscore that should be elements, set attributeChar to empty string.
fix
xmlify(obj, { attributeChar: '' })
affects: >=1.0.0
gotchaPluralized arrays are wrapped in singular element by default — e.g., an array 'comments' becomes <comments><comment>...</comment></comments>. To disable, set wrapArrays: false.
fix
xmlify(obj, { wrapArrays: false })
affects: >=1.0.0
gotchaDate objects are converted to ISO strings (UTC) by default. Use dateFormat option to change to SQL or JS format.
fix
xmlify(obj, { dateFormat: 'SQL' })
affects: >=1.0.0
gotchanull and undefined values are omitted from output — if you need them represented, preprocess the object.
fix
Manually assign default values before conversion.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: xmlify is not a function
Using named import instead of default import or requiring the module incorrectly.
fix
Use 'const xmlify = require("xmlify")' or 'import xmlify from "xmlify"'.
Error: Unexpected token < in JSON at position 0
Trying to parse xmlify output as JSON — the result is XML, not JSON.
fix
Use xmlify to convert objects to XML, not to JSON. Handle the string as XML.
undefined is not an object (evaluating 'obj.split')
Passing a non-string (e.g., number) as root argument.
fix
Ensure root argument is a string: xmlify(obj, 'rootName').
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
26
Resources
packagexmlify
xmlify — npm install xmlify · libregistry