back to home

Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.

4,972 stars
612 forks
249 issues
CoffeeScript

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing Leonidas-from-XIV/node-xml2js in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/Leonidas-from-XIV/node-xml2js)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

node-xml2js =========== Ever had the urge to parse XML? And wanted to access the data in some sane, easy way? Don't want to compile a C parser, for whatever reason? Then xml2js is what you're looking for! Description =========== Simple XML to JavaScript object converter. It supports bi-directional conversion. Uses sax-js and xmlbuilder-js. Note: If you're looking for a full DOM parser, you probably want JSDom. Installation ============ Simplest way to install is to use npm, just which will download xml2js and all dependencies. xml2js is also available via Bower, just which will download xml2js and all dependencies. Usage ===== No extensive tutorials required because you are a smart developer! The task of parsing XML should be an easy one, so let's make it so! Here's some examples. Shoot-and-forget usage ---------------------- You want to parse XML as simple and easy as possible? It's dangerous to go alone, take this: Can't get easier than this, right? This works starting with 0.2.3. With CoffeeScript it looks like this: If you need some special options, fear not, supports a number of options (see below), you can specify these as second argument: Simple as pie usage ------------------- That's right, if you have been using xml-simple or a home-grown wrapper, this was added in 0.1.11 just for you: Look ma, no event listeners! You can also use from CoffeeScript, further reducing the clutter: But what happens if you forget the keyword to create a new ? In the middle of a nightly coding session, it might get lost, after all. Worry not, we got you covered! Starting with 0.2.8 you can also leave it out, in which case will helpfully add it for you, no bad surprises and inexplicable bugs! Promise usage ------------- Parsing multiple files ---------------------- If you want to parse multiple files, you have multiple possibilities: • You can create one per file. That's the recommended one and is promised to always *just work*. • You can call on your parser object. • You can hope everything goes well anyway. This behaviour is not guaranteed work always, if ever. Use option #1 if possible. Thanks! So you wanna some JSON? ----------------------- Just wrap the object in a call to like this . You get a string containing the JSON representation of the parsed object that you can feed to JSON-hungry consumers. Displaying results ------------------ You might wonder why, using or the output at some level is only . Don't worry, this is not because got lazy. That's because Node uses to convert the object into strings and that function stops after which is a bit low for most XML. To display the whole deal, you can use , which displays the whole result. So much for that, but what if you use eyes for nice colored output and it truncates the output with ? Don't fear, there's also a solution for that, you just need to increase the limit by creating a custom inspector and then you can easily . XML builder usage ----------------- Since 0.4.0, objects can be also be used to build XML: will result in: At the moment, a one to one bi-directional conversion is guaranteed only for default configuration, except for , and options you can redefine to your taste. Writing CDATA is supported via setting the option to . To specify attributes: will result in: Adding xmlns attributes You can generate XML that declares XML namespace prefix / URI pairs with xmlns attributes. Example declaring a default namespace on the root element: Result of : Example declaring non-default namespaces on non-root elements: Result of : Processing attribute, tag names and values ------------------------------------------ Since 0.4.1 you can optionally provide the parser with attribute name and tag name processors as well as element value processors (Since 0.4.14, you can also optionally provide the parser with attribute value processors): The and options accept an of functions with the following signature: The and options accept an of functions with the following signature: Some processors are provided out-of-the-box and can be found in : • : transforms the name to lowercase. (Automatically used when is set to ) • : transforms the first character to lower case. E.g. 'MyTagName' becomes 'myTagName' • : strips the xml namespace prefix. E.g will become 'Bar'. (N.B.: the prefix is NOT stripped.) • : parses integer-like strings as integers and float-like strings as floats E.g. "0" becomes 0 and "15.56" becomes 15.56 • : parses boolean-like strings to booleans E.g. "true" becomes true and "False" becomes false Options ======= Apart from the default settings, there are a number of options that can be specified for the parser. Options are specified by new Parser({optionName: value}) . Possible options are: • (default: ): Prefix that is used to access the attributes. Version 0.1 default was . • (default: ): Prefix that is used to access the character content. Version 0.1 default was . • (default: ) Determines whether or not to use a prefix for elements with no attributes. • (default: ): Trim the whitespace at the beginning and end of text nodes. • (default: ): Normalize all tag names to lowercase. • (default: ): Trim whitespaces inside text nodes. • (default: ): Set this if you want to get the root node in the resulting object. • (default: ): what will the value of empty nodes be. In case you want to use an empty object as a default value, it is better to provide a factory function instead. Without this function a plain object would become a shared reference across all occurrences with unwanted behavior. • (default: ): Always put child nodes in an array if true; otherwise an array is created only if there is more than one. • (default: ): Ignore all XML attributes and only create text nodes. • (default: ): Merge attributes and child elements as properties of the parent, instead of keying attributes off a child attribute object. This option is ignored if is . • (default ): You can specify a callable tha…