mlreportgen.dom.Container class

Package: mlreportgen.dom
Superclasses:

Container of document objects

Description

Creates a container element. Use the mlreportgen.dom.Container.append method to append document elements to the container. Use an mlreportgen.dom.Container object in a report to apply formats to all of the children of the container.

In HTML output, a Container object generates an HTML element of the type specified by its HTMLTag property and containing HTML elements corresponding to its DOM contents. For example, a Container object with the HTMLTag property div and that contains the text Hello World generates this markup:

<div><p><span>Hello World</span></p></div>

The generated HTML container element has the class and style properties specified by the Container object StyleName and Style properties, respectively. The rules of HTML CSS format inheritance assure that the generated children of the Container object inherit the formats specified by the Container object Style and StyleName properties. For example, if the Container object specifies red as its text color and none of its text children specify a color, the text children are colored red.

For Microsoft® Word and PDF report output, a Container object simulates container format inheritance, applying the formats specified by the Container object Style attribute to each child, unless overridden by the child, and then appending the child to the output. Word and PDF output ignore the HTMLTag and StyleName properties of the Container object.

Tip

You can use mlreportgen.dom.Container or mlreportgen.dom.Group objects to produce collections of document elements.

  • Use a container object to apply format inheritance to a set of objects and to create HTML container elements not otherwise supported by the DOM, such as div, section, and article.

  • Use a group object to append the same content in multiple places in a document without cloning the group.

Construction

containerObj = Container() creates a container with an HTML tag name div.

example

containerObj = Container(HTMLtag) creates a container with the specified HTML tag name (for example, div, section, or article).

Input Arguments

expand all

HTML container tag name, specified as a character vector. The name must be an HTML element, such as 'div', 'section', or 'article'.

Note

Word output ignores the HTML container tag.

Output Arguments

expand all

Container of document objects, returned as an mlreportgen.dom.Container object.

Properties

expand all

ID for this document element, specified as a character vector or string scalar. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

This read-only property lists child elements that the container contains.

HTML container tag name, specified as a character vector. The name must be an HTML element, such as 'div', 'section', or 'article'.

Note

Word output ignores the HTML container tag.

Parent of this document element, specified as a DOM object. This property is read-only.

Format specification, specified as an array of format objects. The formats specified by this property override corresponding formats defined by the style sheet style specified by the StyleName property of this element. Formats that do not apply to this element are ignored.

Style name, specified as a character vector. The style name is the name of a style specified in the style sheet of the document or document part to which this element is appended. The specified style defines the appearance of this element in the output document where not overridden by the formats specified by the Style property of this element.

Note

Word output ignores the style name.

Tag for this document element, specified as a character vector or string scalar.

The DOM generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specifying your own tag value can help you to identify where an issue occurred during document generation.

Methods

appendAppend DOM object to container
cloneCopy container object

Examples

collapse all

Create a container object. Word output ignores the HTML container element tag (in this example, the div tag).

import mlreportgen.dom.*;
rpt = Document('MyReport','docx');

c = Container();

Color all of the container text red.

c.Style = {Color('red')};

Append content to the container and append the container to the report.

append(c,Paragraph('Hello'));
append(c,Table(magic(5)));
append(rpt,c);

Close and generate the report.

close(rpt);
rptview(rpt.OutputPath);
Introduced in R2015a