Third parties can create and edit XML files outside Microsoft® Office Visio® that follow the Visio schema. When Visio opens a VDX file, it checks whether the file is trusted (created by Visio) or untrusted (created or edited outside Visio). If the file is untrusted and contains third-party schema references, Visio attempts to validate the file against the appropriate schema. If an untrusted file fails to pass validation, it will be rejected, and the document will not be loaded into Visio. In all cases Visio will validate the file against the Visio schema.
Visio will not load any XML that fails validation, either against the Visio schema or a third-party schema. If an XML file passes schema validation, Visio will load the file even if it contains recoverable errors. When Visio encounters any such XML that is ambiguous or incomplete, it tries to preserve as much information as possible and continues loading the file.
If Visio is unable to load a file, or if it finds errors in the file, it logs the errors it finds in the error or warning log. For details about errors and warnings, see Error and Warning Messages.
Beginning with Microsoft Office Visio 2003, you can test the validity of changes you make to SolutionXML elements without having to reopen the file in Visio by turning on the XMLValidateOnSave registry key. For more information, see Embedding Custom XML in a DatadiagramML file.
Visio follows certain rules for handling untrusted data; these rules are explained in the following sections.
Following are the requirements for the order of elements in an untrusted file:
Page elements appear in the order in which pages appear in the Visio user interface and in the Automation collections.
The order of the Shape elements determines the display-list order of the shapes
The order of Master elements determines how they are arranged on the stencil.
Sparse XML and sparse instances
When you write DatadiagramML, the only element that is absolutely required is the VisioDocument element; Visio will automatically write out everything else required for a Visio document using default units and values. This functionality makes it possible for you to create the minimal XML for a VDX file, and Visio will fill in all the other details that are required for a complete document. You can supply only the elements that you are interested in defining, provided they are properly nested under the VisioDocument element and all IDs are accounted for (for example, elements such as Master, Shape, Page, StyleSheet, and PageSheet require an ID attribute).
Be aware that this also means an XML file that is initially "sparse" can grow in size after you load it in Visio and then save it as a VDX file in Visio. While you can initially write a sparse XML file, you can't actually use Visio to save it in its sparse state. Visio always fills in any missing element information when it saves or emits the file.
A sparse XML file includes only the elements that the developer is interested in declaring. A sparse instance is a shape instance (such as for a master that is a group) that does not have all of its child elements specified. Creating a sparse instance of a shape means specifying the top-level shape in the instance without listing its subshapes.
The following guidelines apply to how Visio handles sparse instances when loading untrusted files:
<Master ID='0'>
<Shapes>
<Shape ID='5'>
<Shapes>
<Shape ID='6'/>
<Shape ID='7'/>
</Shapes>
</Shape>
</Shapes>
</Master>
The following XML would be incorrect and would produce a warning indicating duplicate elements:
<Shape ID='1' Master='0'/>
<Shape ID='2' Master='0'/>
The following XML is correct because it takes into account the additional IDs that will be used for the other shape instances:
<Shape ID='1' Master='0'/>
<Shape ID='4' Master='0'/>
Del='1'
. These elements do not get created, their content is ignored, and any child elements are also treated as deleted (even if the children don't have the Del attribute, or if they have Del='0'
). No warnings are generated.Note Well-constructed masters have exactly one immediate child element in a page
When loading untrusted files, Visio enforces internal consistency between a cell element's formula and its value. For most cases where the formula and the value don't match, Visio automatically recalculates the formula to re-create the value and does not generate a warning message.
Following are some Visio behaviors:
F='5/0'
) and the element also contains a value, the value is assigned to the cell, but Visio generates a warning message.
Note To examine the value in a cell that contains 'No Formula', you must either use Automation or examine it indirectly in the ShapeSheet by referencing it from another cell.
A valid value format for the RGB attribute is #RRGGBB, where RR, GG, and BB represent the 00 to FF color component hexadecimal values. If Visio detects an invalid RGB attribute, it does the following:
Note RGB data is an attribute for the ColorEntry element in the color table and can also be the element value for a cell that has a COLOR data type unit.
Invalid style-linkage attributes
In cases where untrusted DatadiagramML files have invalid style-linkage attributes, these linkages cannot be verified by schema-level validation and must be detected and repaired by Visio to keep the model in memory consistent.
The attributes LineStyle, FillStyle, and TextStyle are style-linkage attributes. Their data is a number that specifies the ID of the style to be inherited from.
When Visio detects an invalid style-linkage attribute, the following occurs:
A style-linkage attribute is considered invalid if any of the following are true:
For example:
<StyleSheet ID='5' LineStyle='6' FillStyle='6' TextStyle='6'/>
<StyleSheet ID='6' LineStyle='5' FillStyle='5' TextStyle='5'/>
Visio enables third parties to easily create and edit DatadiagramML cell elements by providing default Unit attributes for cell elements that are of a known unit type and logging informative error messages when unexpected data is encountered.
Most cell elements have known and dedicated result types, such as boolean, color, distance, angle, and so on. These cells are termed non-void cells. Other cells have no intrinsic result type and are intended to hold any type of result
Note To find out the default unit of a particular element, see that element's topic in this reference.
Following are some of the ways that Visio handles unexpected data when verifying the Unit attribute associated with a cell element:
For example, the following two XML snippets produce identical results and no warnings. (The default unit for the Angle element is DA, default angle units.):
<Angle Unit='STR'>bats can fly</Angle>
<Angle F='"bats can fly"'/>
In both cases, the internal result is:
formula = 'bats can fly'
value = 0 deg.
error = #VALUE!
Visio emits Unit attributes only when they are different than the default unit for that particular element.
For information about how Visio handles text when loading an untrusted DatadiagramML file, see Working with a Shape's Text in DatadiagramML.