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
muslnode 18–226 runs
build_error
glibcnode 18–226 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);
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.
fixEnsure `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`).
fixAccess elements from the parsed array, such as `parsedXML[0]` for the first root element, or iterate through the array to process multiple roots.
Audit
Dependencies
No dependency data recorded yet.