728x90
https://www.npmjs.com/package/js2xmlparser
Install
The easiest way to install js2xmlparser is to use npm: npm install js2xmlparser
.
Alternatively, you may download the source from GitHub and copy it to a folder named "js2xmlparser" within your "node_modules" directory.
Usage
The js2xmlparser module contains one function which takes the following arguments:
root
- the XML root element's name (string, mandatory)data
- the data to be converted to XML; while the data object can contain arrays, it cannot itself be an array (object or JSON string, mandatory)declaration
- XML declaration options (object, optional)include
- specifies whether an XML declaration should be included (boolean, optional, default: true)encoding
- value of XML encoding attribute in declaration; a value of null represents no encoding attribute (string, optional, default: "UTF-8")
attributeString
- the name of the property representing an element's attributes; note that any property with a name equal to the attribute string is ignored except in the context of XML attributes (string, optional, default: "@")valueString
- the name of the property representing an element's value; note that any property with a name equal to the value string is ignored except in the context of supplying a value for a tag containing attributes (string, optional, default: "#")aliasString
- the name of the property representing an element's alias; the name of the containing element will be replaced with the alias (string, optional, default: "=")prettyPrinting
- pretty-printing options (object, optional)enabled
- specifies whether pretty-printing is enabled (boolean, optional, default: true)indentString
- indent string (string, optional, default: "\t")
convertMap
- maps object types (as given by theObject.prototype.toString.call
method) to functions to convert those objects to a particular string representation;*
can be used as a wildcard for all types of objects (object, optional, default: {})useCDATA
- specifies whether strings should be enclosed in CDATA tags; otherwise, illegal XML characters will be escaped (boolean, optional, default: false)
options
- module options (object, optional)
Usage
The following example illustrates the basic usage of js2xmlparser:
var js2xmlparser = require("js2xmlparser");
var data = {
"firstName": "John",
"lastName": "Smith"
};
console.log(js2xmlparser("person", data));
> <?xml version="1.0" encoding="UTF-8"?>
> <person>
> <firstName>John</firstName>
> <lastName>Smith</lastName>
> </person>
반응형
'◇ 보관글' 카테고리의 다른 글
남아 바지 패턴 (0) | 2015.06.23 |
---|---|
공공병원에 관한 글 (0) | 2015.06.12 |
이윤기의 그리스로마신화 2 (0) | 2015.06.05 |
톨스토이 부활 (0) | 2015.06.05 |
황금고리 (0) | 2015.06.03 |