{"id":14874,"library":"react-native-html-parser","title":"React Native HTML Parser","description":"This package provides a DOM/XML parser for React Native, Titanium, and browser environments, based on the `xmldom` library. The current and only stable version is 0.1.0, which was last published over 6 years ago. It aims to offer a W3C DOM Level 2 Core-compatible API, including `DOMParser` and `XMLSerializer`, along with `xmldom`-specific extensions for error handling. Due to its age and lack of maintenance, it is unlikely to be compatible with modern JavaScript, Node.js, or React Native environments and may contain unpatched security vulnerabilities inherited from its `xmldom` dependency. Developers should consider more actively maintained alternatives for parsing HTML in React Native.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/g6ling/react-native-html-parser","tags":["javascript","dom","xml","html","parser","DOMParser","XMLSerializer","ReactNative"],"install":[{"cmd":"npm install react-native-html-parser","lang":"bash","label":"npm"},{"cmd":"yarn add react-native-html-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-native-html-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core parsing engine, providing DOMParser and XMLSerializer functionality.","package":"xmldom","optional":false}],"imports":[{"note":"ESM import is shown, but the package primarily used CommonJS `require` given its age. The default `require` exports an object with `DOMParser` as a property.","wrong":"const DOMParser = require('react-native-html-parser').DOMParser;","symbol":"DOMParser","correct":"import { DOMParser } from 'react-native-html-parser';"},{"note":"This is the most common CommonJS `require` pattern seen in examples. Note the casing variation for the imported variable (`DomParser` vs `DOMParser`).","wrong":"import DomParser from 'react-native-html-parser';","symbol":"DOMParser","correct":"const DomParser = require('react-native-html-parser').DOMParser;"},{"note":"While an ESM import might appear to work in some bundlers, the package was designed for CommonJS. The `XMLSerializer` is another export from the main module.","wrong":"import { XMLSerializer } from 'react-native-html-parser';","symbol":"XMLSerializer","correct":"const { XMLSerializer } = require('react-native-html-parser');"}],"quickstart":{"code":"import React, { Component } from 'react-native';\nimport { DOMParser } from 'react-native-html-parser';\n\nclass TestReactNativeHtmlParser extends Component {\n    componentDidMount() {\n        let html = `<html>\n                        <body>\n                            <div id=\"b a\">\n                                <a href=\"example.org\">\n                                <div class=\"inA\">\n                                    <br>bbbb</br>\n                                </div>\n                            </div>\n                            <div class=\"bb a\">\n                                Test\n                            </div>\n                        </body>\n                    </html>`;\n        \n        // Instantiate DOMParser and parse the HTML string\n        let doc = new DOMParser().parseFromString(html, 'text/html');\n        \n        // Example usage of parsed document methods\n        console.log('QuerySelect #b .inA:', doc.querySelect('#b .inA'));\n        console.log('getElementsByTagName a:', doc.getElementsByTagName('a'));\n        console.log('QuerySelect #b a[href=\"example.org\"]:', doc.querySelect('#b a[href=\"example.org\"]'));\n        console.log('getElementsByClassName a (non-strict):', doc.getElementsByClassName('a', false));\n\n        // Serialize the document back to a string\n        // const serializer = new XMLSerializer(); // Not directly exported from main module in all cases\n        // console.log('Serialized HTML:', serializer.serializeToString(doc));\n    }\n\n    render() {\n        return null; // For demonstration, no UI rendered\n    }\n}\n\nexport default TestReactNativeHtmlParser;","lang":"javascript","description":"Demonstrates parsing an HTML string, querying elements using various methods like `querySelect` and `getElementsByTagName`, and briefly shows the document structure. Note that `XMLSerializer` import might need adjustment depending on the exact build environment."},"warnings":[{"fix":"Migrate to a currently maintained HTML parsing library designed for React Native, such as `html-react-parser` or `@react-native-html/parser`.","message":"This package has been abandoned for over 6 years (last published v0.1.0). It is highly unlikely to be compatible with modern React Native, Node.js, or browser environments due to significant changes in these platforms.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Due to the abandoned status of `react-native-html-parser`, there are no direct fixes. Users must migrate to an alternative library that is actively maintained and addresses `xmldom`'s security issues or uses a different parsing engine.","message":"The underlying `xmldom` library, upon which this package is based, has multiple known security vulnerabilities, including XML injection, prototype pollution, and improper input validation. The `xmldom` maintainers advise migrating to `@xmldom/xmldom` for security fixes.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"If attempting to use this package in an old React Native project, ensure React Native imports are compatible with the specific version of React Native in use. For new projects, avoid this package entirely.","message":"Examples in the README use deprecated React Native imports (e.g., `import { View, Text } from 'react-native'`). Modern React Native requires specific imports for components or hooks.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Thoroughly test parsing results for critical use cases. Consider alternatives based on more robust parsers like `parse5` (e.g., `react-native-parse-html`).","message":"The `xmldom` library, and thus `react-native-html-parser`, might not be fully spec-compliant with the latest HTML5 parsing rules, potentially leading to unexpected parsing behavior compared to browser-native `DOMParser` implementations.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Check the HTML/XML source for invalid or unsupported entities. Ensure character encoding is correctly specified if external sources are being parsed. Refer to the linked GitHub issue for potential workarounds or to preprocess HTML.","cause":"This error occurs when the parser encounters an XML or HTML entity (e.g., `&nbsp;`, `&mdash;`) that it does not recognize or that is malformed.","error":"[xmldom error] entity not found: ~~~~~"}],"ecosystem":"npm"}