Inheritance
Inheritance
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Microsoft Visio shapes can inherit sections, rows, and cells from parent sheets. A Shape element that inherits from a Master element is called an instance of the Master element. An instance inherits all the elements of the master. Additionally, a Shape element can inherit from a StyleSheet element and inherit the style's line, fill, and text properties. (A Master element doesn't inherit from styles, but the PageSheet or Shape elements contained in them do.) A StyleSheet and PageSheet element can also inherit from another StyleSheet element.
The inheritance relationships are established in an XML for Visio file by means of attributes. The following table describes the attributes used to establish inheritance between a shape, a master, and a style. (Some of the attributes listed in the table are also associated with other elements. For example, the Page element also has an ID attribute that identifies it within its container, but it is unrelated to inheritance.)
Attribute |
In element |
Attribute description |
ID |
Master and StyleSheet |
A unique ID within the object's container. An integer value. |
Master |
Shape |
The ID of the master that the shape inherits from. Top-level shapes on a page that are instances of a master must have a valid Master attribute. Mutually exclusive with the MasterShape attribute. |
MasterShape |
Shape |
This is the ID of a shape in a Master element that this shape inherits. Establishes a link between an instance of a shape and its master shape. Subshapes of an instance group shape must have this attribute. Mutually exclusive with the Master attribute. |
LineStyle |
Shape, StyleSheet, PageSheet, DocumentSheet |
ID of the line style that this shape or style inherits from. |
FillStyle |
Shape, StyleSheet, PageSheet, DocumentSheet |
ID of the fill style that this shape or style inherits from. |
TextStyle |
Shape, StyleSheet, PageSheet, DocumentSheet |
ID of the text style that this shape or style inherits from. |
Del |
Shape |
Del is a boolean attribute. It is only meaningful if the shape is part of a master instance. If 1 (true), the shape instance is deleted locally. |
Master and MasterShape attributes
Shape elements use the Master and MasterShape attributes to establish inheritance from a Master element. For example, a shape that inherits from a master has a Master attribute whose value is the ID of the Master element. The Shape inherits all the subelements of the Shape element contained in the Master.
A Master element is often composed of one Shapes element with multiple Shape elements that can, in turn, contain additional Shapes elements. The IDs of a Master element's shapes and subshapes are all unique within the Master element. In an instance of a master, the master's subshapes can be re-expressed for the purposes of local overrides or local deletions. However, those subshapes must have their own ID attribute that is unique within the instance's page.
To maintain a link back to the Master element's shapes, overridden shapes must have a separate attribute called MasterShape. The value of this attribute is the ID of the Shape in the Master that this local shape is overriding.
For example, the following code describes a master that is a group:
<Master ID='4' NameU='MasterShapeExample' ...>
...
<Shapes>
<Shape ID='5' Type='Group'>
...
<Shapes>
<Shape ID='6' Type='Shape'>
...
<Fill>
<FillForegnd>#ff9900</FillForegnd>
...
</Fill>
...
</Shape>
...
</Shapes>
</Shape>
</Shapes>
</Master>
The following is an instance of that master with a shape that refers to a shape in the master (in the MasterShape attribute):
<Shape ID='10' NameU='MasterShapeExample' Type='Group' Master='4'>
...
<Shapes>
<Shape ID='11' Type='Shape' MasterShape='6'>
...
<Fill>
<FillForegnd>3</FillForegnd>
...
</Fill>
</Shape>
</Shapes>
</Shape>
FillStyle, LineStyle, and TextStyle attributes
A Shape, PageSheet, DocumentSheet, or StyleSheet element can inherit from up to three other StyleSheet elements. Three attributes of a sheet element—FillStyle, TextStyle, and LineStyle—can refer to a StyleSheet element by ID. When a sheet element inherits from a StyleSheet element, it only inherits elements relevant to the attribute. For example, when a Shape element contains a TextStyle attribute, it only inherits elements that affect text, such as Para, Char, Tabs, and TextBlock.
Note If an instance does not specify a particular style-inheritance attribute, those properties are inherited from the master shape, or the style that master shape inherits. If a non-instance does not specify a particular style-inheritance attribute, Style 0 is used. (Style 0 is defined by the default document and cannot be modified in the user interface or through Automation.)
Local overrides
A Shape element that inherits from a Master element is called an instance of the Master. An instance inherits all the elements of the master. Therefore, the instance in an XML for Visio file does not explicitly express the elements that it inherits. By locally overriding an element you can block inheritance of that element.
Consider the following XML:
<Master ID='0'>
...
<XForm>
<PinX> 1.0 </PinX>
<PinY> 2.0 </PinY>
</XForm>
...
</Master>
...
<Shape ID='99' Master='0'/>
Shape 99 inherits all the elements of Master 0. It does not explicitly express its PinX and PinY elements, but the Shape element behaves as if they were present. If a Shape element does explicitly express an inherited element, that component is locally overridden in the instance. Consider the following code:
<Master ID='0'>
...
<XForm>
<PinX> 1.0 </PinX>
<PinY> 2.0 </PinY>
</XForm>
...
</Master>
...
<Shape ID='99' Master='0'>
<XForm>
<PinX> 2.0 </PinX>
</XForm>
</Shape>
In this case, Shape 99 still inherits its master's PinY element value, but it has locally overridden the value of PinX to 2.0.
Local deletion
A Shape element can also suppress the appearance of an element in an instance. When an instance suppresses a component, that component is locally deleted. Consider this example:
<Master ID='0'>
<Shapes>
<Shape ID='5' Type='Group' ...>
<Shapes>
<Shape ID='6' Type='Shape' ...>
...
</Shape>
<Shape ID='7' Type='Shape' ...>
...
</Shape>
</Shapes>
</Shape>
</Shapes>
</Master>
In this case, the Master element is a group that contains two shapes. To suppress one of the shapes on the shape instance, use the Del attribute. For example, the following would suppress a shape (ID='2') in the instance of the group:
<Shapes>
<Shape ID='1' Type='Group' Master='0'>
...
<Shapes>
<Shape ID='2' Type='Shape' MasterShape='6' Del='1'>
...
</Shape>
<Shape ID='3' Type='Shape' MasterShape='7'>
...
</Shape>
</Shapes>
</Shape>
</Shapes>
Inheritance states
The following table describes all the possible inheritance states in which the sheet elements can exist.
Note Every Visio document is based on a default document with a built-in StyleSheet element with the ID of 0. Style 0 is defined by the default document and cannot be modified in the user interface or through Automation. If a sheet does not explicitly inherit from a Master or StyleSheet element, it implicitly inherits from StyleSheet ID = '0'. All absent document-level elements also inherit from Style 0.
When Visio reads an XML for Visio file, it ignores any StyleSheet element with the ID='0'. It always uses its built-in Style 0 when loading an XML for Visio file.