xml
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The npm package "xml" is a fast and simple JavaScript-based XML generator or builder for Node projects. This tool supports attributes, CDATA, and more, making it a comprehensive solution for generating XML strings in your Node.js applications.
To use the "xml" package, you first need to install it using npm by running the command npm install xml
in your terminal.
The primary API function of this module is xml(xmlObject, options)
, which takes an object representation of your XML data (the xmlObject
) and an optional options
object, then returns an XML string.
Here's a basic usage example:
var xml = require('xml');
var xmlString = xml({a: 1});
In the above example, the xml
function will turn {a: 1}
into <a>1</a>
, with keys becoming tag names and values becoming the tag content.
To set attributes or include CDATA sections in your XML, you can use special keys _attr
and _cdata
. Here's an example:
var xmlString = xml({a: { _attr: { attr:'hi'}, _cdata: "I'm not escaped" }});
The above will result in: <a attr="hi"><![CDATA[I'm not escaped]]></a>
You can also generate and process large XML documents in a streaming fashion, add XML declaration, and use indent options for easy reading.
The documentation for the "xml" package can be found in the README file on the package's GitHub page, located at https://github.com/dylang/node-xml.
Details on how to use the API, install the package, run tests, and contribute to the project are all covered in the documentation. Examples of usage can also be found in the examples directory.