# selection.extractOoxml

> Capture a nonempty current or addressed selection as OOXML with its structure, context, and package dependencies.



- Member path: `doc.selection.extractOoxml(…)`
- Mutates document: no
- Idempotency: `idempotent`
- Supports tracked mode: no
- Supports dry run: no

## Expected result

Returns the selected OOXML, structural placement, source provenance, and required relationships and parts without changing the document.

## Input schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "SelectionTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "selection"
        },
        "start": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "end": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "coordinateSpace": {
          "$ref": "#/$defs/TextCoordinateSpace"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "start",
        "end"
      ]
    },
    "SelectionPoint": {
      "description": "A point in the document. Use {kind:'text', blockId, offset} for character positions or {kind:'nodeEdge', node:{kind:'block', nodeType, nodeId}, edge:'before'|'after'} for block boundaries.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "text"
            },
            "blockId": {
              "type": "string"
            },
            "offset": {
              "type": "integer",
              "minimum": 0
            },
            "story": {
              "$ref": "#/$defs/StoryLocator"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "blockId",
            "offset"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "nodeEdge"
            },
            "node": {
              "$ref": "#/$defs/SelectionEdgeNodeAddress"
            },
            "edge": {
              "enum": [
                "before",
                "after"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "node",
            "edge"
          ]
        }
      ]
    },
    "StoryLocator": {
      "description": "Story scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterSlot"
            },
            "section": {
              "$ref": "#/$defs/SectionAddress"
            },
            "headerFooterKind": {
              "enum": [
                "header",
                "footer"
              ]
            },
            "variant": {
              "enum": [
                "default",
                "first",
                "even"
              ]
            },
            "resolution": {
              "enum": [
                "effective",
                "explicit"
              ]
            },
            "onWrite": {
              "enum": [
                "materializeIfInherited",
                "editResolvedPart",
                "error"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "section",
            "headerFooterKind",
            "variant"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterPart"
            },
            "refId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "refId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "footnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "endnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "textbox"
            },
            "textboxId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "textboxId"
          ]
        }
      ]
    },
    "SectionAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "section"
        },
        "sectionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "sectionId"
      ]
    },
    "SelectionEdgeNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "listItem",
            "table",
            "tableOfContents",
            "sdt",
            "image"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "TextCoordinateSpace": {
      "enum": [
        "visible",
        "tracked"
      ]
    }
  },
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "at": {
          "oneOf": [
            {
              "$ref": "#/$defs/SelectionTarget"
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "const": "tableCells"
                },
                "tableId": {
                  "type": "string",
                  "minLength": 1
                },
                "start": {
                  "type": "object",
                  "properties": {
                    "rowIndex": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "columnIndex": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "rowIndex",
                    "columnIndex"
                  ]
                },
                "end": {
                  "type": "object",
                  "properties": {
                    "rowIndex": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "columnIndex": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "rowIndex",
                    "columnIndex"
                  ]
                },
                "story": {
                  "$ref": "#/$defs/StoryLocator"
                }
              },
              "additionalProperties": false,
              "required": [
                "kind",
                "tableId",
                "start",
                "end"
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "at"
      ]
    },
    {
      "type": "object",
      "properties": {
        "selection": {
          "const": "current"
        }
      },
      "additionalProperties": false,
      "required": [
        "selection"
      ]
    }
  ]
}
```

## Output schema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "SelectionTarget": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "selection"
        },
        "start": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "end": {
          "$ref": "#/$defs/SelectionPoint"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        },
        "coordinateSpace": {
          "$ref": "#/$defs/TextCoordinateSpace"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "start",
        "end"
      ]
    },
    "SelectionPoint": {
      "description": "A point in the document. Use {kind:'text', blockId, offset} for character positions or {kind:'nodeEdge', node:{kind:'block', nodeType, nodeId}, edge:'before'|'after'} for block boundaries.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "text"
            },
            "blockId": {
              "type": "string"
            },
            "offset": {
              "type": "integer",
              "minimum": 0
            },
            "story": {
              "$ref": "#/$defs/StoryLocator"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "blockId",
            "offset"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "nodeEdge"
            },
            "node": {
              "$ref": "#/$defs/SelectionEdgeNodeAddress"
            },
            "edge": {
              "enum": [
                "before",
                "after"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "node",
            "edge"
          ]
        }
      ]
    },
    "StoryLocator": {
      "description": "Story scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "body"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterSlot"
            },
            "section": {
              "$ref": "#/$defs/SectionAddress"
            },
            "headerFooterKind": {
              "enum": [
                "header",
                "footer"
              ]
            },
            "variant": {
              "enum": [
                "default",
                "first",
                "even"
              ]
            },
            "resolution": {
              "enum": [
                "effective",
                "explicit"
              ]
            },
            "onWrite": {
              "enum": [
                "materializeIfInherited",
                "editResolvedPart",
                "error"
              ]
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "section",
            "headerFooterKind",
            "variant"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "headerFooterPart"
            },
            "refId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "refId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "footnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "endnote"
            },
            "noteId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "noteId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "story"
            },
            "storyType": {
              "const": "textbox"
            },
            "textboxId": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "storyType",
            "textboxId"
          ]
        }
      ]
    },
    "SectionAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "section"
        },
        "sectionId": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "sectionId"
      ]
    },
    "SelectionEdgeNodeAddress": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "block"
        },
        "nodeType": {
          "enum": [
            "paragraph",
            "heading",
            "listItem",
            "table",
            "tableOfContents",
            "sdt",
            "image"
          ]
        },
        "nodeId": {
          "type": "string"
        },
        "story": {
          "$ref": "#/$defs/StoryLocator"
        }
      },
      "additionalProperties": false,
      "required": [
        "kind",
        "nodeType",
        "nodeId"
      ]
    },
    "TextCoordinateSpace": {
      "enum": [
        "visible",
        "tracked"
      ]
    }
  },
  "type": "object",
  "properties": {
    "formatVersion": {
      "const": 1
    },
    "at": {
      "oneOf": [
        {
          "$ref": "#/$defs/SelectionTarget"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "tableCells"
            },
            "tableId": {
              "type": "string"
            },
            "start": {
              "type": "object",
              "properties": {
                "rowIndex": {
                  "type": "integer"
                },
                "columnIndex": {
                  "type": "integer"
                }
              },
              "additionalProperties": false,
              "required": [
                "rowIndex",
                "columnIndex"
              ]
            },
            "end": {
              "type": "object",
              "properties": {
                "rowIndex": {
                  "type": "integer"
                },
                "columnIndex": {
                  "type": "integer"
                }
              },
              "additionalProperties": false,
              "required": [
                "rowIndex",
                "columnIndex"
              ]
            },
            "story": {
              "$ref": "#/$defs/StoryLocator"
            }
          },
          "additionalProperties": false,
          "required": [
            "kind",
            "tableId",
            "start",
            "end"
          ]
        }
      ]
    },
    "evaluatedRevision": {
      "type": "string"
    },
    "fragment": {
      "type": "object",
      "properties": {
        "placement": {
          "enum": [
            "inline",
            "blocks",
            "table"
          ]
        },
        "xml": {
          "type": "string"
        },
        "namespaces": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "table": {
          "type": "object",
          "properties": {
            "tableId": {
              "type": "string"
            },
            "gridColumnCount": {
              "type": "integer"
            },
            "cells": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "rowIndex": {
                    "type": "integer"
                  },
                  "columnIndex": {
                    "type": "integer"
                  },
                  "gridSpan": {
                    "type": "integer"
                  },
                  "vMerge": {
                    "enum": [
                      "none",
                      "restart",
                      "continue"
                    ]
                  }
                },
                "additionalProperties": false,
                "required": [
                  "rowIndex",
                  "columnIndex",
                  "gridSpan",
                  "vMerge"
                ]
              }
            }
          },
          "additionalProperties": false,
          "required": [
            "tableId",
            "gridColumnCount",
            "cells"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "placement",
        "xml",
        "namespaces"
      ]
    },
    "source": {
      "type": "object",
      "properties": {
        "story": {
          "oneOf": [
            {
              "$ref": "#/$defs/StoryLocator"
            },
            {
              "type": "null"
            }
          ]
        },
        "partUri": {
          "type": "string"
        },
        "paragraphStyleId": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "story",
        "partUri",
        "paragraphStyleId"
      ]
    },
    "context": {
      "type": "object",
      "properties": {
        "xml": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tableMerges": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "selectedRowIndex": {
                "type": "integer"
              },
              "columnIndex": {
                "type": "integer"
              },
              "restartRowIndex": {
                "type": "integer"
              },
              "restartCellPropertiesXml": {
                "type": "string"
              }
            },
            "additionalProperties": false,
            "required": [
              "selectedRowIndex",
              "columnIndex",
              "restartRowIndex",
              "restartCellPropertiesXml"
            ]
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "xml"
      ]
    },
    "dependencies": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "sourcePartUri": {
            "type": "string"
          },
          "relationshipId": {
            "type": "string"
          },
          "relationshipType": {
            "type": "string"
          },
          "target": {
            "type": "string"
          },
          "targetMode": {
            "enum": [
              "Internal",
              "External"
            ]
          },
          "contentType": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "dataBase64": {
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "sourcePartUri",
          "relationshipId",
          "relationshipType",
          "target",
          "targetMode",
          "contentType"
        ]
      }
    },
    "diagnostics": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "code",
          "message"
        ]
      }
    }
  },
  "additionalProperties": false,
  "required": [
    "formatVersion",
    "at",
    "evaluatedRevision",
    "fragment",
    "source",
    "context",
    "dependencies",
    "diagnostics"
  ]
}
```

## Pre-apply throws

- `INVALID_INPUT`
- `INVALID_TARGET`
- `TARGET_NOT_FOUND`
- `INVALID_CONTEXT`
- `AMBIGUOUS_MATCH`
- `PRECONDITION_FAILED`
- `RESOURCE_LIMIT`

## Non-applied receipt codes

- None

