select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

invalid_xml_document

SQLSTATE
2200M
Condition name
invalid_xml_document
Class
Data Exception
Source macro
ERRCODE_INVALID_XML_DOCUMENT
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>2200M</h1>

At a glance

This catalogue member denotes an invalid XML document. PostgreSQL 18.6 has a core xml_parse document branch that reports invalid XML document, and the contrib/xml2 XSLT path reports the same SQLSTATE for a failed source document or stylesheet parse. These are distinct emitters from the 2200L document-option wrapper.

Meaning

This member names an invalid XML document condition from a concrete document parser guard. In core xml_parse, a failed xmlCtxtReadDoc parse reports 2200M when the original XML option was DOCUMENT; when the original option was CONTENT, the same parser failure reports 2200N. The separate contrib/xml2 functions use 2200M when parsing the input document or stylesheet as XML. The core xml_errsave helper passes these results to errsave: an ErrorSaveContext stores the error and returns, while an ordinary context throws; this soft-error path is distinct from the direct ERROR branches in contrib/xml2.

Messages

The core branch raises ERROR with primary invalid XML document. The contrib/xml2 branches raise ERROR with primary error parsing XML document or error parsing stylesheet as XML document. The cited branches do not provide a fixed DETAIL or HINT template; libxml2 context can be attached dynamically. Do not replace these messages with 2200L’s not an XML document.

Diagnosis

Use the actual SQLSTATE, message, detail, and context to distinguish document-level failure from invalid content (2200N), comment (2200S), or processing instruction (2200T). Inspect whether the producer is core xml_parse or contrib/xml2, then correct the named document or stylesheet. These emitters are source-confirmed here; no natural runtime was run.

Response

Use the actual message and parser context to repair the invalid document; do not substitute a 2200L fix without confirming the emitted SQLSTATE.

When this branch raises ERROR, an explicit transaction must first be recovered with ROLLBACK or ROLLBACK TO SAVEPOINT for a savepoint established before the statement; in autocommit, retry only the corrected action after the failed statement completes. See the transaction and retry guide for this boundary rule.

Versions

The locked catalogue records this condition from 8.3.0; fixed source coverage is PostgreSQL 18.6.

Sources

Fixed core source: src/backend/utils/adt/xml.c#L1780-1862. The separate contrib/xml2/xslt_proc.c#L84-100 paths parse an XML document and stylesheet. The shared xml_errsave/errsave helper defines the soft-error versus ordinary-throw behavior. The structured evidence record retains both emitters, message roles, and scope boundaries. Core availability depends on USE_LIBXML; no natural XML case was run for this page.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

2200M is invalid_xml_document in SQLSTATE Class 22.

Method: Read fixed definition.

src.errcodes.18.6

The core xml_parse document branch maps a failed libxml document parse to 2200M with primary invalid XML document.

Method: Read the document parse failure branch.

Limits: The dynamic libxml diagnostic may be attached separately; no single static DETAIL template should be invented.

src.path.xml-invalid-document

The core xml_errsave helper passes XML errors to errsave: an ErrorSaveContext stores the error and returns, while an ordinary context throws; this soft-error path is distinct from the direct ERROR branches in contrib/xml2.

Method: Read the xml_errsave comment and errsave call.

Limits: This source distinction describes error propagation; it is not a natural runtime observation.

The contrib/xml2 XSLT path also reports invalid XML document when its parser reports an error.

Method: Read the complete xml2 error branch.

Limits: This path requires the xml2 extension and is separate from core XML constructors.

src.path.xml2-document

Core XML branches are compiled under the USE_LIBXML feature guard; availability depends on the server build.

Method: Read surrounding fixed source guards.

Limits: Source confirmation is not a natural runtime observation.

src.path.xml-invalid-document

The locked catalogue records 2200M from 8.3.0 without proving an exact implementation introduction date.

Method: Use catalogue boundary.

src.errcodes.18.6

Message templates

ERROR · message.core-document

Primary

invalid XML document
ERROR · message.xml2-document

Primary

error parsing XML document

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:903f9dba778fcb35e7a054d962b… · English manual source