> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spojit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XML Tools

> Parse, convert, validate, and format XML data.

The XML Tools connector provides operations for working with XML: parsing, converting to and from JSON, formatting, and validation.

<Note>No connection required; this utility connector works out of the box.</Note>

## Tools

<AccordionGroup>
  <Accordion title="to-json: Convert XML to JSON">
    <ParamField body="xml" type="string" required>
      XML string to convert.
    </ParamField>

    <ParamField body="ignoreAttributes" type="boolean" default="false">
      Ignore XML attributes.
    </ParamField>

    <ParamField body="attributePrefix" type="string" default="@_">
      Prefix for attribute keys in JSON.
    </ParamField>

    <ParamField body="textNodeName" type="string" default="#text">
      Key name for text nodes.
    </ParamField>

    <ParamField body="preserveOrder" type="boolean" default="false">
      Preserve element order in output.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "xml": "<catalog><book id=\"1\"><title>Dune</title><price>12.99</price></book><book id=\"2\"><title>Neuromancer</title><price>9.99</price></book></catalog>"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "value": {
        "catalog": {
          "book": [
            { "@_id": "1", "title": "Dune", "price": 12.99 },
            { "@_id": "2", "title": "Neuromancer", "price": 9.99 }
          ]
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="from-json: Convert JSON to XML">
    <ParamField body="data" type="any" required>
      JSON data to convert.
    </ParamField>

    <ParamField body="rootName" type="string" default="root">
      Root element name.
    </ParamField>

    <ParamField body="attributePrefix" type="string" default="@_">
      Prefix that identifies attributes.
    </ParamField>

    <ParamField body="textNodeName" type="string" default="#text">
      Key name for text content.
    </ParamField>

    <ParamField body="declaration" type="boolean" default="true">
      Include XML declaration.
    </ParamField>

    <ParamField body="pretty" type="boolean" default="true">
      Format with indentation.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": {
        "user": {
          "@_role": "admin",
          "name": "Alice",
          "email": "alice@example.com"
        }
      },
      "declaration": true,
      "pretty": true
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "result": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user role=\"admin\">\n  <name>Alice</name>\n  <email>alice@example.com</email>\n</user>"
    }
    ```
  </Accordion>

  <Accordion title="parse: Parse XML with metadata">
    Parse XML and return structured data with metadata.

    <ParamField body="xml" type="string" required>
      XML string to parse.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "xml": "<order id=\"789\"><item sku=\"A1\">Widget</item><total>29.99</total></order>"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "rootElement": "order",
      "data": {
        "order": {
          "@_id": "789",
          "item": {
            "@_sku": "A1",
            "#text": "Widget"
          },
          "total": 29.99
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="prettify: Format XML">
    Format XML with indentation for readability.

    <ParamField body="xml" type="string" required>
      XML string to format.
    </ParamField>

    <ParamField body="indent" type="number" default="2">
      Number of indentation spaces.
    </ParamField>

    <ParamField body="encoding" type="enum" default="utf8">
      Output encoding for the `result` field: `utf8` (default) or `base64` (for email attachments, SFTP uploads, or knowledge-base embedding). The response includes an `encoding` tag.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "xml": "<root><name>Alice</name><age>30</age></root>",
      "indent": 4
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "result": "<root>\n    <name>Alice</name>\n    <age>30</age>\n</root>"
    }
    ```
  </Accordion>

  <Accordion title="minify: Minify XML">
    Remove all unnecessary whitespace from XML.

    <ParamField body="xml" type="string" required>
      XML string to minify.
    </ParamField>

    <ParamField body="encoding" type="enum" default="utf8">
      Output encoding for the `result` field: `utf8` (default) or `base64` (for email attachments, SFTP uploads, or knowledge-base embedding). The response includes an `encoding` tag.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "xml": "<root>\n  <name>Alice</name>\n  <age>30</age>\n</root>"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "result": "<root><name>Alice</name><age>30</age></root>"
    }
    ```
  </Accordion>

  <Accordion title="validate: Validate XML">
    Check if a string is valid XML.

    <ParamField body="xml" type="string" required>
      XML string to validate.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "xml": "<root><name>Alice</name></root>"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "valid": true
    }
    ```
  </Accordion>

  <Accordion title="extract: Extract element by path">
    Extract a specific element using dot-notation path.

    <ParamField body="xml" type="string" required>
      XML string.
    </ParamField>

    <ParamField body="path" type="string" required>
      Dot-notation path (e.g., `root.items.item`).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "xml": "<catalog><books><book>Dune</book><book>Neuromancer</book></books></catalog>",
      "path": "catalog.books.book"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "value": ["Dune", "Neuromancer"]
    }
    ```
  </Accordion>
</AccordionGroup>
