webdev_xml_formatter
Format and validate XML documents with customizable indentation, attribute sorting, and comment removal. Check well-formedness and get element statistics.
Instructions
XML Formatter and Validator. Pretty-print, beautify, and validate XML with configurable indentation (spaces or tabs), attribute sorting, comment removal, and an optional XML declaration. Pass the document as the xml parameter. Use webdev_xml_to_json when you need to convert XML into a JSON object rather than tidy the markup; use webdev_sql_formatter or webdev_graphql_formatter for those languages. Regex-based parser (not a full XML processor), so DTDs and complex namespaces are not resolved and malformed markup is reported as an error with the original text echoed back. Runs locally via a Node bridge: read-only, non-destructive, contacts no external service, rate-limited (30 requests/minute for anonymous callers). Returns the formatted XML, a validity flag, error and warning lists, and element/attribute/size statistics.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xml | Yes | The XML document to format or validate. Must not be blank. | |
| format | No | Pretty-print with indentation when true; emit compact single-line XML when false. | |
| validate | No | Check well-formedness and report mismatched or unclosed tags as errors. | |
| indentSize | No | Number of spaces per indent level (ignored when indentType is tabs). | |
| indentType | No | Whether each indent level is spaces or a tab character. | spaces |
| removeComments | No | Strip XML comments from the output when true. | |
| preserveWhitespace | No | Keep original text whitespace when true; trim element text when false. | |
| sortAttributes | No | Sort the attributes of each element alphabetically by name when true. | |
| addDeclaration | No | Prepend an XML declaration (version 1.0, UTF-8) when one is absent. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| original | No | The submitted XML, echoed back. | |
| formatted | No | The formatted XML, or the original input when parsing failed. | |
| isValid | No | Whether the XML parsed as well-formed. | |
| errors | No | Parse error messages (empty when valid). | |
| warnings | No | Non-fatal warnings. | |
| stats | No | Node counts and size metrics for the document. |