Validate XML
validate_xmlValidates an XML document for well-formedness, namespace correctness, and the entity-based attacks that arrive as XML.
Use this before parsing XML you received, and when an XML document is being rejected by something that will not say why.
Do not eyeball this. Four classes of genuinely invalid XML are accepted by ordinary well-formedness checkers, so "it validated" does not mean what it appears to:
(1) Two root elements. <a/><b/> is not a valid XML document; XML permits exactly one outermost element. Concatenated records hit this constantly.
(2) Undeclared namespace prefixes. <x:a> with no xmlns:x is well-formed as raw XML and invalid under Namespaces in XML — so it passes a syntax check and is then rejected by XPath, XSLT, SOAP and every schema validator.
(3) Undeclared entities. XML predefines only five (< > & ' "). is an HTML entity and is simply undefined in XML.
(4) A bare &, almost always arriving inside a URL.
Security findings, which are the reason to run this on input you did not write: external entity declarations (XXE — reported with the URI they point at and the remediation for Python, Java and .NET), nested entity expansion (billion laughs), parameter entities (the out-of-band XXE vehicle), external DTD references (an SSRF vector and a runtime dependency on someone else's host), and any DOCTYPE at all, since hardened parsers reject them outright.
Input: input, the raw XML text as a string. Up to 1,000,000 bytes.
Returns: valid (no errors), parseable (whether a conforming parser would accept it — deliberately separate, because a duplicate key parses fine and still means two different things), a diagnostics array where each entry has a 1-based line and column, a stable rule code, a message, an excerpt showing the offending line with a caret under the column, a fixHint, and blocksParse; plus counts and format-specific stats. Rule codes are stable and safe to branch on; messages are not.
Safety: nothing is resolved, fetched or expanded. External XML entities are reported, never retrieved; alias bombs are detected without being expanded; no schema or DTD is fetched over the network. Payloads are validated in memory and never stored.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | The raw document text, not a parsed object — the findings are properties of the text. Up to 1,000,000 bytes. |