选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 22 数据异常

2200M invalid_xml_document

ERROR 源码确认 参考 未实测

类别
Class 22 数据异常
严重等级
ERROR
条件名
invalid_xml_document
宏名称
ERRCODE_INVALID_XML_DOCUMENT
启用版本
8.3
状态
活跃

版本覆盖

速览

该目录成员表示 XML 文档无效。PostgreSQL 18.6 的核心 xml_parse 文档分支会报告 invalid XML document,而 contrib/xml2 的 XSLT 路径在源文档或样式表解析失败时也使用同一 SQLSTATE。这些发出点不同于 2200L 的文档选项包装器。

含义

本成员来自具体的文档解析 guard,表示 XML 文档无效。在核心 xml_parse 中,xmlCtxtReadDoc 解析失败且原始 XML 选项为 DOCUMENT 时报告 2200M;原始选项为 CONTENT 时,同一解析失败报告 2200N。独立的 contrib/xml2 函数在把输入文档或样式表作为 XML 解析失败时使用 2200M。核心 xml_errsave 会把这些结果交给 errsave:传入 ErrorSaveContext 时保存错误并正常返回,普通上下文则抛出错误;这条软错误路径不同于 contrib/xml2 直接抛出 ERROR 的分支。

报文

核心分支以 ERROR 报告 primary:invalid XML documentcontrib/xml2 分支以 ERROR 报告 primary:error parsing XML documenterror parsing stylesheet as XML document。引用分支没有固定 DETAIL 或 HINT 模板;libxml2 上下文可能动态附加。不要把这些报文替换成 2200L 的 not an XML document

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 invalid XML document

来源:src/backend/utils/adt/xml.c @ REL_18_6

主消息 error parsing XML document

来源:contrib/xml2/xslt_proc.c @ REL_18_6

诊断

结合实际 SQLSTATE、message、detail 和 context,区分文档级失败与内容(2200N)、注释(2200S)或处理指令(2200T)错误。检查产生报文的是核心 xml_parse 还是 contrib/xml2,再修正报文指向的文档或样式表。本页已确认这些源码发出路径,但未运行自然案例。

处理

根据实际报文和解析器上下文修正无效文档;未确认实际 SQLSTATE 前不要套用 2200L 的处理。

该分支抛出 ERROR 时,显式事务应先用 ROLLBACK 恢复,或对语句前已建立的保存点执行 ROLLBACK TO SAVEPOINT,再重试;自动提交下只在失败语句结束后重试修正后的动作。事务边界规则见事务与重试指南。

版本

锁定目录从 8.3.0 起记录该条件;固定源码覆盖 PostgreSQL 18.6。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 2200M is invalid_xml_document in SQLSTATE Class 22.

    核实方式Read fixed definition.

    来源src/backend/utils/errcodes.txt

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

    核实方式Read the document parse failure branch.

    不覆盖The dynamic libxml diagnostic may be attached separately; no single static DETAIL template should be invented.

    来源src/backend/utils/adt/xml.c

  • 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.

    核实方式Read the xml_errsave comment and errsave call.

    不覆盖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.

    核实方式Read the complete xml2 error branch.

    不覆盖This path requires the xml2 extension and is separate from core XML constructors.

    来源contrib/xml2/xslt_proc.c

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

    核实方式Read surrounding fixed source guards.

    不覆盖Source confirmation is not a natural runtime observation.

    来源src/backend/utils/adt/xml.c

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

    核实方式Use catalogue boundary.

    来源src/backend/utils/errcodes.txt

同类错误代码

Class 22 数据异常 下的其他成员。