react-xml-viewer is a React component designed for pretty-printing and displaying XML strings in a user-friendly, formatted manner. The current stable version is 3.0.4. The library has an active release cadence, with recent updates addressing security vulnerabilities (CVEs), ensuring compatibility with newer React versions (e.g., React 19), and adding new features like line numbers and improved collapsing functionality. Its key differentiators include extensive customization options for appearance via a theming prop, the ability to make XML collapsible, and a dedicated prop for handling invalid XML input. It also ships with TypeScript types, enhancing developer experience in TypeScript projects. It leverages `fast-xml-parser` for its underlying XML processing, and regular updates help maintain security and performance.
npm install react-xml-viewerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates rendering a complex XML string using `XMLViewer` with various styling, collapsing, and line number options, including custom theme and invalid XML handling.
Consult the `react-xml-viewer` v2.0.0 changelog and update component props and usage patterns accordingly. Ensure `react` and `react-dom` peer dependencies meet the requirements (>=16.8.4).
Update `react-xml-viewer` to version 2.0.4 or higher and correct the prop name to `initialCollapsedDepth`.
Ensure the XML string passed to the `xml` prop is well-formed. Consider validating XML on the server-side or providing a custom `invalidXml` component to guide users.
Upgrade `react-xml-viewer` to version 3.0.2 or newer immediately to mitigate these security risks.
Always use the latest stable version of `react-xml-viewer` to ensure compatibility with the most recent stable React releases. If using an older React version, ensure `react-xml-viewer`'s peer dependencies are met.
Use `const XMLViewer = require('react-xml-viewer').default;` for CommonJS imports or switch to `import XMLViewer from 'react-xml-viewer';` in an ESM context.Ensure the `xml` prop always receives a valid XML string. For optional XML, use conditional rendering or provide a default empty string: `<XMLViewer xml={xmlString ?? ''} />`.Update `react-xml-viewer` to version 2.0.4 or higher and correct the prop name to `initialCollapsedDepth`.