not an XML document
SQLSTATE 2200L is raised when an XML-related function or cast receives input that is not a well-formed XML document. A valid XML document must have exactly one root element.
- 1Passing a string with multiple root elements or no root element to an XML function that requires a document
- 2Passing XML content that is well-formed as a fragment but not as a standalone document
Casting a string with multiple root elements to XML.
SELECT XMLPARSE(DOCUMENT '<a/><b/>'); -- two root elements
expected output
ERROR: invalid XML document
Fix 1
Wrap content fragments in a single root element
WHEN When the input is a fragment rather than a full document.
SELECT XMLPARSE(DOCUMENT '<root><a/><b/></root>');
Why this works
Wrapping in a root element produces a valid XML document with exactly one root.
Fix 2
Use XMLPARSE(CONTENT ...) for XML fragments
WHEN When the input is a well-formed fragment but not a full document.
SELECT XMLPARSE(CONTENT '<a/><b/>');
Why this works
CONTENT mode accepts XML fragments without requiring a single root element.
Class 22 — Data Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev