xml_to_yaml
Parse an XML string into YAML, preserving the root element name as the top-level key.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | XML string to convert. |
Response
| Field | Type | Description |
|---|---|---|
output | string | The converted YAML string. |
Example
{
"input": "<person id=\"1\"><name>Alice</name><tag>admin</tag><tag>user</tag></person>"
}
Result:
{
"output": "person:\n '@id': '1'\n name: Alice\n tag:\n - admin\n - user\n"
}
Errors
Each failure carries a precise code in the response. Argument-schema and server errors are JSON-RPC protocol errors; a rejected value is returned as a tool result with isError: true (so the agent can read the code and self-correct).
| Code | When | Delivered as |
|---|---|---|
invalid_arguments | input is missing or not a string. | protocol error (invalid_params) |
invalid_xml | The input string is not valid XML or has no root element. | tool error (isError) |
internal_error | An unexpected server error. | protocol error (internal_error) |
Mapping Convention
| XML | YAML |
|---|---|
Element <foo> | Mapping key foo |
Attribute id="1" | @id: '1' in the element's mapping |
| Repeated elements with same tag | YAML sequence under that tag key |
Text-only element <foo>bar</foo> | Scalar string foo: bar |
| Mixed element (text + children) | $text key added to the element's mapping |
Self-closing element <foo/> | foo: null |
Notes
- All attribute and text values are returned as strings. Type inference is not performed.
- Round-trips between
xml_to_yamlandyaml_to_xmlare not guaranteed to be lossless.