2200M
Read PG 18 manual ↗invalid_xml_document
- SQLSTATE
- 2200M
- Condition name
- invalid_xml_document
- Class
- Data Exception
- Source macro
- ERRCODE_INVALID_XML_DOCUMENT
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
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.
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.
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.
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.
The locked catalogue records 2200M from 8.3.0 without proving an exact implementation introduction date.
Method: Use catalogue boundary.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·- src/backend/utils/adt/xml.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - contrib/xml2/xslt_proc.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/xml.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
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