Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#11743·langchainjs

bug(core): XMLOutputParser loses parents and siblings after self-closing tags

Author: To3akaRinCreated Sep 27, 2026Updated Sep 27, 2026

Description

XMLOutputParser loses parent and sibling elements when valid XML contains a self-closing tag. For example, the nested document below returns only { c: "y" }. Replacing <a/> with <a></a> preserves the full tree.

Example Code

typescript
import { XMLOutputParser } from "@langchain/core/output_parsers";

const parser = new XMLOutputParser();
const result = await parser.parse(
  "<root><group><a/><b>x</b></group><c>y</c></root>"
);
console.dir(result, { depth: null });

Actual:

typescript
{ c: "y" }

Expected:

typescript
{ root: [{ group: [{ a: "" }, { b: "x" }] }, { c: "y" }] }

There is no exception: the result silently loses data. The same problem occurs with Markdown-wrapped XML and streamed output.

Cause

The bundled SAX parser emits both an open event and a close event for a self-closing element. parseXMLMarkdown() skips pushing that element onto its stack, so its close event pops the parent instead. Later elements can then replace the root result.

Checked other resources

Searched GitHub issues and open PRs for XMLOutputParser and XML self-closing tags. The CDATA report #6666 concerns a different SAX event and is unrelated to this stack imbalance.

System Info

  • Reproduced on main at 5d509ad4b8a5ed9dd4b83020b4c103ac8a69859c (@langchain/core package version 1.2.13).
  • Node.js 24.18.0, pnpm 10.14.0, macOS.
  • No model provider, credentials, or network requests are needed.

Source: langchain-ai/langchainjs

View original on GitHubView discussion on GitHub