{"id":16278,"library":"xml-parse","title":"XML Parser, Stringifier, and DOM","description":"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.","status":"abandoned","version":"0.4.0","language":"javascript","source_language":"en","source_url":"git://github.com/MauriceConrad/XML-Parser","tags":["javascript","xml","xml parser","xml dom","xml stringify","xml parse","xml stringifier","dom","html"],"install":[{"cmd":"npm install xml-parse","lang":"bash","label":"npm"},{"cmd":"yarn add xml-parse","lang":"bash","label":"yarn"},{"cmd":"pnpm add xml-parse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only, last updated over 6 years ago, and does not support ES Modules.","wrong":"import xml from 'xml-parse'","symbol":"xml","correct":"const xml = require('xml-parse')"},{"note":"The parse method is accessed via the default CommonJS export. It is not a named export.","wrong":"import { parse } from 'xml-parse'","symbol":"parse","correct":"const xml = require('xml-parse'); xml.parse(xmlString)"},{"note":"The stringify method is accessed via the default CommonJS export. It is not a named export.","wrong":"import { stringify } from 'xml-parse'","symbol":"stringify","correct":"const xml = require('xml-parse'); xml.stringify(parsedXml, 2)"},{"note":"The DOM constructor is accessed via the default CommonJS export. It is not a named export.","wrong":"import { DOM } from 'xml-parse'","symbol":"DOM","correct":"const xml = require('xml-parse'); new xml.DOM(parsedXml)"}],"quickstart":{"code":"const xml = require(\"xml-parse\");\n\n// 1. Parse an XML string (can handle invalid XML too)\nconst xmlString = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><item>Hello</item><item>World</item></root>';\nconst parsedXML = xml.parse(xmlString);\nconsole.log('Parsed XML (raw object structure):', JSON.stringify(parsedXML, null, 2));\n\n// 2. Access elements using the simplified DOM\nconst xmlDoc = new xml.DOM(parsedXML);\n\n// The root is always an array, so access the first element if expecting a single root\nconst rootElement = xmlDoc.document.childNodes[1]; // Skip the XML declaration\n\nif (rootElement && rootElement.tagName === 'root') {\n  console.log('\\nRoot element tagName:', rootElement.tagName);\n  const items = rootElement.getElementsByTagName('item');\n  items.forEach((item, index) => {\n    console.log(`Item ${index + 1} text:`, item.childNodes[0].text);\n  });\n} else {\n  console.log('\\nCould not find expected root element.');\n}\n\n// 3. Stringify the parsed object structure back to an XML string\nconst stringifiedXML = xml.stringify(parsedXML, 2); // 2 spaces for indentation\nconsole.log('\\nStringified XML:\\n', stringifiedXML);","lang":"javascript","description":"Demonstrates parsing a valid XML string, accessing its structure via the simplified DOM, and then stringifying it back, showing the core functionalities."},"warnings":[{"fix":"Migrate to a currently maintained XML parsing library.","message":"The 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.","severity":"breaking","affected_versions":">=0.4.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use `const xml = require('xml-parse');` in CommonJS environments. For ESM projects, consider a modern alternative with ESM support.","message":"The package is CommonJS-only and relies on `require()`. It does not officially support ES Modules (`import`) syntax, which is standard in modern JavaScript environments.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `const xml = require('xml-parse');` is correctly placed and the module is accessible. Verify you are not using ES Module `import` syntax.","cause":"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.","error":"TypeError: xml.parse is not a function"},{"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.","cause":"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`).","error":"TypeError: Cannot read properties of undefined (reading 'tagName')"}],"ecosystem":"npm"}