# XML exc c14n subtree

`xml-exc-c14n-subtree` · version 1.0.0 · Structured formats · free, no key needed

Exclusive XML Canonicalization 1.0 of one selected element and its descendants.

**Use when you need to: exclusive canonicalization of an xml subtree · canonicalize one xml element and descendants · exc-c14n document subset by element name.**

## Decide before calling

Read the [versioned contract](/v1/tools/xml-exc-c14n-subtree/versions/1.0.0) and the supported scope below. Reuse `xml-exc-c14n-subtree@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `xml-exc-c14n-subtree@1.0.0` for exclusive canonicalization of an xml subtree. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- exclusive canonicalization of an xml subtree
- canonicalize one xml element and descendants
- exc-c14n document subset by element name
- strip unused ancestor namespaces from xml element
- xml fragment exclusive canonical form
- select element occurrence for exclusive c14n
- inclusive prefix list on xml subtree apex
- exclusive c14n of a named element

## Not supported

- inclusive canonicalization of a document subset
- arbitrary xpath beyond one element name
- xml digital signature creation
- repairing a non-canonical fragment

## Behavior

- Selects the occurrence-th element whose qualified name matches element exactly, in document order, and canonicalizes that element and its descendants with Exclusive XML Canonicalization 1.0.
- Omitted occurrence means 1. occurrence must be an integer from 1 to 1024; a value outside that range is invalid_input, and a name that does not occur that many times is invalid_input with details.reason element_not_found.
- The subtree apex starts a fresh rendered-namespace map containing only the prebound xml prefix. Ancestor namespace declarations are emitted only when this element visibly uses them or the prefix is in the inclusive list. Ancestor xml:lang, xml:space, and xml:base are not copied.
- Document-level comments and processing instructions outside the selected element are not part of the result. Comment content that contains "--" or ends with "-" throws invalid_input even when with_comments is false or omitted.
- Serialization matches the whole-document tool: code-point attribute order, expanded empty elements, the same escapes, no Unicode normalization, and utf8_bytes equal to the UTF-8 length of canonical_xml. The returned element is the selector text and occurrence is the index used.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.

## Input

- `xml` (string, required): min length 1; max length 8192
- `element` (string, required): min length 1; max length 128
- `occurrence` (integer, optional): min 1; max 1024
- `with_comments` (boolean, optional)
- `inclusive_prefixes` (array of string, optional): max items 16; each min length 1; each max length 128; each pattern `^(#default|[A-Za-z_][A-Za-z0-9._-]*)$`

## Output

- `canonical_xml` (string, required): min length 1; max length 8192
- `utf8_bytes` (integer, required): min 7; max 8192
- `element` (string, required): min length 1; max length 128
- `occurrence` (integer, required): min 1; max 1024

## Limits

- max input bytes: 8192
- max canonical bytes: 8192
- max output bytes: 49152
- max depth: 32
- max nodes: 1024
- max attributes per element: 32
- max inclusive prefixes: 16
- max name bytes: 128

## Example

Request input:

```json
{
  "xml": "<n1:elem1 xmlns:n1=\"http://b.example\">\n    content\n</n1:elem1>",
  "element": "n1:elem1"
}
```

Response:

```json
{
  "result": {
    "canonical_xml": "<n1:elem1 xmlns:n1=\"http://b.example\">\n    content\n</n1:elem1>",
    "utf8_bytes": 62,
    "element": "n1:elem1",
    "occurrence": 1
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "xml-exc-c14n-subtree",
  "version": "1.0.0",
  "input": {
    "xml": "<n1:elem1 xmlns:n1=\"http://b.example\">\n    content\n</n1:elem1>",
    "element": "n1:elem1"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/xml-exc-c14n-subtree/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"xml":"<n1:elem1 xmlns:n1=\"http://b.example\">\n    content\n</n1:elem1>","element":"n1:elem1"}'
```

The machine-readable contract is at [/v1/tools/xml-exc-c14n-subtree/versions/1.0.0](/v1/tools/xml-exc-c14n-subtree/versions/1.0.0).

### CLI

```sh
node cli.mjs run xml-exc-c14n-subtree 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [XML exc c14n canonicalize](/tools/xml-exc-c14n-canonicalize): Exclusive XML Canonicalization 1.0 of a whole document, with an optional inclusive prefix list.
- [XML exc c14n validate](/tools/xml-exc-c14n-validate): Check whether XML is already in Exclusive XML Canonicalization 1.0 form.
- [Xpath10 count](/tools/xpath10-count): Count the nodes in an XPath 1.0 node-set from location paths, axes, predicates, namespaces and union.
- [Xpath10 paths](/tools/xpath10-paths): List the canonical XPath 1.0 path of each node in a location-path node-set, in document order.
- [Xpath10 select](/tools/xpath10-select): Select an XPath 1.0 node-set from location paths, axes, predicates, namespaces and union, in document order.
- [Gitconfig format](/tools/gitconfig-format): Format git config sections as canonical text with escapes and subsections.
