Insert Content - Maple Help

DocumentTools

 InsertContent
 insert content into a worksheet

 Calling Sequence InsertContent(content) InsertContent(content, opts)

Parameters

 content - {string, XML tree} ; string or XML tree structure containing a valid XML description of a worksheet or task template opts - (optional); one or more keyword options as described below

Returns

 • A mapping of embedded component identities in the content, which may have been substituted upon insertion in order to avoid conflicting with identities of embedded components already existing in the currently open worksheet.
 • The mapping will be in the form of either a two-column Array of strings or a table. The form is specified by the output option.
 • In the case of a two-column Array the first column's entries are the identities as strings of the components in the input, and the second column's entries are the corresponding identities as strings of the inserted components.
 • In the case of a returned table the indices are the identities as strings of the input components and the corresponding values are the identities as strings of the inserted components.

Options

 • minimal : truefalse
 Specifies whether to insert minimal content (true) or default content (false). The default is true.
 • output : identical(Array,table)
 Specifies whether to return the mapping of embedded component identity names as a two column Array or as a table. The default is Array. See the Returns section.
 • state : string
 Associates a "state" string with the inserted content.  The value can be any string, including the name of the "State" variable as set by DocumentTools:-Components:-State, or a serialized encoding of a data structure as given by sprintf("%m",data).  Use DocumentTools:-GetProperty("",'contentstate') before calling InsertContent to see if you are about to replace previously inserted content -- if you want to initialize the new content based on some of the settings of the old content.
 • replaceid : string
 Instead of inserting the worksheet content at the next available cursor location, replace the previously inserted worksheet content that contains the component with the given identifier.  The identifier can be that of any component within the task grouping, such as, "Button0".  The entire task grouping will be replaced with the new worksheet content, not just the named component.
 • validate : truefalse
 Specifies whether to validate the XML against a schema. The default is false.

Description

 • The InsertContent function inserts input worksheet content into the currently open Worksheet or Document at the next available cursor location.
 • The input worksheet content is given as an XML string or tree structure.
 • Embedded component's identities may be substituted upon insertion to avoid identity conflicts. Such substitutions are also done for any literal instances (as names or strings) of the identities of the renamed components in the action code of any embedded components in the content.
 • The content may be generated using commands from the Component Constructors and Layout Constructors packages.

Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Layout}\right):$
 > $\mathrm{InsertContent}\left(\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Textfield}\left(\mathrm{InlinePlot}\left(\mathrm{plot}\left(\mathrm{sin}\right)\right)\right)\right)\right)\right)$

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Components}\right):$
 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Textfield}\left(\mathrm{Button}\left("My Caption",\mathrm{identity}="Button0"\right)\right)\right)\right)$
 {\mathrm{xml}}{≔}{\mathrm{_XML_Worksheet}}{}\left({\mathrm{_XML_Group}}{}\left({"view"}{=}{"presentation"}{,}{"hide-input"}{=}{"false"}{,}{"hide-output"}{=}{"false"}{,}{"inline-output"}{=}{"false"}{,}{"drawlabel"}{=}{"true"}{,}{\mathrm{_XML_Text-field}}{}\left({"alignment"}{=}{"centred"}{,}{"style"}{=}{"Text"}{,}{"layout"}{=}{"Normal"}{,}{\mathrm{_XML_EC-Button}}{}\left({"id"}{=}{"Button0"}{,}{"caption"}{=}{"My Caption"}{,}{"enabled"}{=}{"true"}{,}{"fontcolor"}{=}{"\left[0,0,0\right]"}{,}{"visible"}{=}{"true"}{,}{"show-border"}{=}{"true"}\right)\right)\right)\right) (1)
 > $\mathrm{first}≔\mathrm{InsertContent}\left(\mathrm{xml}\right)$
 $\left[\begin{array}{cc}{"Button0"}& {"Button0"}\end{array}\right]$ (2)

The previous example inserted a component with identity "Button0", so a second insertion of that same content must involve a substitution for that string in order to avoid an identity conflict.

The table form of the returned identity mapping is a convenient mechanism for redirected references to the inserted components.

 > $\mathrm{lookup}≔\mathrm{InsertContent}\left(\mathrm{xml},\mathrm{output}=\mathrm{table}\right)$
 ${\mathrm{lookup}}{≔}{table}{}\left(\left[{"Button0"}{=}{"Button1"}\right]\right)$ (3)

 > $\mathrm{lookup}\left["Button0"\right]$
 ${"Button1"}$ (4)
 > $\mathrm{SetProperty}\left(\mathrm{lookup}\left["Button0"\right],\mathrm{caption},"New Caption",\mathrm{refresh}\right)$
 > 

Compatibility

 • The DocumentTools[InsertContent] command was introduced in Maple 2015.