Skip to main content

xml_to_yaml

Parse an XML string into YAML, preserving the root element name as the top-level key.

Parameters​

ParameterTypeRequiredDescription
inputstringYesXML string to convert.

Response​

FieldTypeDescription
outputstringThe 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).

CodeWhenDelivered as
invalid_argumentsinput is missing or not a string.protocol error (invalid_params)
invalid_xmlThe input string is not valid XML or has no root element.tool error (isError)
internal_errorAn unexpected server error.protocol error (internal_error)

Mapping Convention​

XMLYAML
Element <foo>Mapping key foo
Attribute id="1"@id: '1' in the element's mapping
Repeated elements with same tagYAML 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_yaml and yaml_to_xml are not guaranteed to be lossless.