Registry / serialization / xml-parse

xml-parse

JSON →
library0.4.0jsnpmunverified

The `xml-parse` library, currently at version 0.4.0 and last published over 6 years ago, provides a tolerant parser, stringifier, and a simplified Document Object Model (DOM) for XML and HTML. Its key differentiator is its ability to handle malformed or invalid XML gracefully by always returning an array of root elements, even if there's only one. The library's components (parser, stringifier, and DOM) are designed to be lightweight and modular. It exclusively uses CommonJS `require` syntax, with no explicit mention or support for modern ES Modules. Given its low version number and the lack of recent updates, the package is no longer actively maintained and should be considered abandoned.

npm install xml-parse
INSTALL
IMPORT
SIG · XML-PARSE
X
xml-parse
serializationjavascriptv0.4.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

xml
const xml = require('xml-parse')
import xml from 'xml-parse'
The package is CommonJS-only, last updated over 6 years ago, and does not support ES Modules.
parse
const xml = require('xml-parse'); xml.parse(xmlString)
import { parse } from 'xml-parse'
The parse method is accessed via the default CommonJS export. It is not a named export.
stringify
const xml = require('xml-parse'); xml.stringify(parsedXml, 2)
import { stringify } from 'xml-parse'
The stringify method is accessed via the default CommonJS export. It is not a named export.
DOM
const xml = require('xml-parse'); new xml.DOM(parsedXml)
import { DOM } from 'xml-parse'
The DOM constructor is accessed via the default CommonJS export. It is not a named export.

Demonstrates parsing a valid XML string, accessing its structure via the simplified DOM, and then stringifying it back, showing the core functionalities.

const xml = require("xml-parse"); // 1. Parse an XML string (can handle invalid XML too) const xmlString = '<?xml version="1.0" encoding="UTF-8"?><root><item>Hello</item><item>World</item></root>'; const parsedXML = xml.parse(xmlString); console.log('Parsed XML (raw object structure):', JSON.stringify(parsedXML, null, 2)); // 2. Access elements using the simplified DOM const xmlDoc = new xml.DOM(parsedXML); // The root is always an array, so access the first element if expecting a single root const rootElement = xmlDoc.document.childNodes[1]; // Skip the XML declaration if (rootElement && rootElement.tagName === 'root') { console.log('\nRoot element tagName:', rootElement.tagName); const items = rootElement.getElementsByTagName('item'); items.forEach((item, index) => { console.log(`Item ${index + 1} text:`, item.childNodes[0].text); }); } else { console.log('\nCould not find expected root element.'); } // 3. Stringify the parsed object structure back to an XML string const stringifiedXML = xml.stringify(parsedXML, 2); // 2 spaces for indentation console.log('\nStringified XML:\n', stringifiedXML);
Debug
Known issues
breakingThe package is abandoned. It was last published over 6 years ago (version 0.4.0) and is not maintained. Consider using actively maintained alternatives like `fast-xml-parser` or `@rgrove/parse-xml` for modern projects.
fix
Migrate to a currently maintained XML parsing library.
affects: >=0.4.0
gotchaThe `xml.parse` method always returns an array of nodes, even for valid XML documents with a single root. This is done to accommodate invalid XML with multiple root elements.
fix
Always treat the result of `xml.parse` as an array and access the first element (e.g., `parsedXML[0]`) if you expect a single root node.
affects: >=0.1.0
gotchaThe package is CommonJS-only and relies on `require()`. It does not officially support ES Modules (`import`) syntax, which is standard in modern JavaScript environments.
fix
Use `const xml = require('xml-parse');` in CommonJS environments. For ESM projects, consider a modern alternative with ESM support.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: xml.parse is not a function
Attempting to call `parse` on an undefined `xml` object, often due to incorrect `require` path or environment issues, or trying to use ES Modules `import` syntax.
fix
Ensure `const xml = require('xml-parse');` is correctly placed and the module is accessible. Verify you are not using ES Module `import` syntax.
TypeError: Cannot read properties of undefined (reading 'tagName')
Attempting to access properties like `tagName` directly on the result of `xml.parse()` without realizing it returns an array (e.g., `parsedXML.tagName` instead of `parsedXML[0]?.tagName`).
fix
Access elements from the parsed array, such as `parsedXML[0]` for the first root element, or iterate through the array to process multiple roots.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
xml-parse — npm install xml-parse · libregistry