Round-Tripping DatadiagramML Files

You can save Microsoft Visio drawings, stencils, and templates as XML files and then open them again in Visio without any loss of information. This is called round-tripping.

However, after Visio opens an XML file that was created in another application or opens a DatadiagramML file that was edited in another application and then resaves the document as a DatadiagramML file, the files are not guaranteed to be identical, although there should be no loss of data.

The following cases illustrate some differences that occur when an XML file that is created in another application or when a DatadiagramML file that is edited in another application is saved in Visio.

White space

White space is not preserved in DatadiagramML files except within elements whose data type is String, including Text elements. Visio also preserves white space for any Solution XML or unknown XML because of the default xml:space='preserve' setting in all VDX files. In all other cases, for example in cell elements whose data type is NUM, white space is not preserved. By default, Visio typically does not display any formatting, such as carriage returns and tab indents, in the source code of XML files. This can make these files hard to read inside a general text editor such as Notepad. To instruct Visio to display formatting such as indents of child elements in XML files or other formatting that makes your files easier to read, modify the following registry key.

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Visio\Application\XMLEmitIndents

To improve readability in Notepad and other text editors, set the value of XMLEmitIndents to 1.

Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall the operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.

Elements that represent Visio ShapeSheet spreadsheet cells

Visio always emits local cell elements that have an explicit unit, value, and formula. If a third-party application omits portions of the element, Visio either picks default values or infers correct values for the missing components. Consider the following fragment that might be emitted from a third-party application.

<PinX F='1'/>

Because only a formula was specified, Visio assigns the formula to the PinX element and then evaluates the formula to determine the value. Because the formula evaluates to a constant, Visio flags the element as a constant. A unit of measure was not specified, so Visio uses the default unit for the cell, which is inches (the default length unit or DL). When the file is resaved, the previous fragment appears similar to the following.

<PinX>1</PinX>

Note

If the unit of measure is explicitly set in the ShapeSheet spreadsheet and is different from the default unit, Visio writes out the Unit attribute.

Elements that represent rows

A DatadiagramML file can contain a series of elements that represent indexed rows. Consider the following file fragment.

<Scratch IX='3'>
   <X> 3 <X/>
</Scratch>
<Scratch IX='1'>
   <X> 1 <X/>
</Scratch>

When Visio reads the file and resaves it, it appears similar to the following.

<Scratch IX='0'>
   <X F='No Formula'>0</X>
   <Y F='No Formula'>0</Y>
   ...
</Scratch> 
<Scratch IX='1'>
   <X>1</X>
   <Y F='No Formula'>0</Y>
   ...
</Scratch> 
<Scratch IX='2'>
   <X F='No Formula'>0</X>
   <Y F='No Formula'>0</Y>
   ...
</Scratch> 
<Scratch IX='3'>
   <X>3</X>
   <Y F='No Formula'>0</Y>
   ...
</Scratch>

Visio always writes indexed rows out in index order. If the original sequence of rows was indexed sparsely (there were gaps in the sequence), Visio implicitly creates the missing rows.

Note

Text rows will not work as expected if the rows are not listed in ascending order.

Named rows have no specific order. If a DatadiagramML file contains a series of named rows, their order is not guaranteed when the file is round-tripped.

Geom elements

Geometry sections follow the same round-tripping rules as indexed rows. Indexed sections can appear in any order, but when round-tripped, they are written out in index order and the sparse sections are implicitly created.

For more information about Geom elements, see Working with Geometry in DatadiagramML.

Text elements

In the Visio engine, a block of text can contain ASCII control characters that represent tabs, line breaks, paragraph breaks, and field positions.

An ASCII 9, ASCII 10, or ASCII 13 character indicating a tab, paragraph break, or line break, respectively, is emitted as a normal ASCII character into DatadiagramML. These characters are considered legal Unicode characters by all XML parsers.

Any other ASCII control character between ASCII 0 and ASCII 31 (other than ASCII 9, 10, and 13) is considered an illegal Unicode character by some XML parsers. As a result, when you save a file that contains these control characters, Visio converts them into question-mark characters (?) and warns you about their existence.

For more information about working with text, see Working with a Shape's Text in DatadiagramML.

Miscellaneous

A third-party application can omit a document-level element from a DatadiagramML file, such as DocumentProperties or any of the document level child elements, such as Author. However, when the DatadiagramML file is round-tripped, Visio creates a document-level element for all non-empty document properties. For example, a DatadiagramML file can omit the TimeSaved element, but the round-tripped DatadiagramML file contains a TimeSaved element with an appropriate value.

Round-Tripping DatadiagramML Files between Microsoft Visio 2010 and Microsoft Office Visio 2007

Microsoft Visio 2010 introduces several New ShapeSheet cells and functions.

Support of new Visio 2010 ShapeSheet cells in Visio 2007

These new cells do not present a problem for documents saved in binary (.vsd) file format. However, the new XML elements that represent the new cells would not be recognized by Visio in files saved in XML format (.vdx files), because they are not included in the Visio 2007 XML schema. As a result, if you attempt to open a Visio 2010 file that is saved in XML format in Visio 2007, you get a warning if the XML is trusted (created by Visio); the file will fail to open if the XML is untrusted (created or edited outside Visio).

To address this issue, the elements that represent the new cells reference the "v14" namespace alias, and thus are considered to be unknown XML. The file opens, but Visio ignores the contents of these elements.

<Shape ID='5' ...>
            ...
            <Layout>
                  <ShapePermeableX>1</ShapePermeableX>
                  <ShapePermeableY>0</ShapePermeableY>
                  ...
            </Layout>
            <v14:Layout>
                  <v14:Relationships F='Inh'>0</v14:Relationships>
                  <v14:DisplayLevel>25000</v14:DisplayLevel>
            </v14:Layout>
            ...
      </Shape>

Support of new Visio 2010 ShapeSheet functions in Visio 2007

When Visio 2007 loads an XML file that was created in Visio 2010, it cannot parse new Visio 2010 ShapeSheet functions, and therefore does not recognize any formulas that contain references to new cells or new functions. To address this issue, when you save a Visio 2010 file in VDX format, anytime that a cell contains references to new Visio 2010 formulas and therefore requires that those cells be declared in extended XML format, Visio modifies the file as follows, and as shown in the accompanying example:

  • In the regular XML section, Visio writes the last valid computed value, but not the formula.

  • In the extended XML section, designated by the "x:" namespace, Visio writes both the last valid computed value and the new formula.

<Shape ID='1' ...>
            <XForm>
                  <PinX>4</PinX>
                  <PinY>8.125</PinY>
                  ...
            </XForm>
            <v14:XForm>
                  <v14:PinX F='NEWFUNC()+1.5'>4</v14:PinX>
                  <v14:PinY F='NEWFUNC2()*Width'>8.125</v14:PinY>
            </x:XForm>
            ...
      </Shape>

This ensures that Visio 2007 loads VSD and VDX files in the same manner. When it loads the files, Visio writes the extended XML sections as string data stored with an individual shape, as it would any other unknown XML. The last valid computed values are correct, but the formulas that are specific to Visio 2010 are re-evaluated in the event a user opens, edits, and then resaves the file in Visio 2007, which forces Visio to recalculate. In the event that you open a Visio 2010 VDX file in Visio 2007, save it as a Visio 2007 VDX file, and then reopen it in Visio 2010, the formulas in the extended XML sections of the VDX file match the original formulas specific to Visio 2010 only if both of the following conditions are met:

  1. The last valid computed values in the regular and extended XML sections match each other exactly (indicating that no recalculation has taken place).

  2. The current value is a trivial formula (for example, a formula that evaluates to a constant).