An XML for Visio overview

An XML for Visio overview

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.

An XML for Visio file is an XML (Extensible Markup Language) document that contains all the components of a Microsoft Visio binary file. Similar to the way you can access a Visio document through Automation or from the ShapeSheet window, you can use XML and supporting tools to access data in an XML for Visio file.

XML (Extensible Markup Language) is the universal format for structured documents and data on the Web.

Just as HTML (Hypertext Markup Language) provides a way to display information on different hardware and software platforms by creating a standard set of fixed, non-customizable tags that a browser interprets and displays, XML provides a way to create documents with custom tags that allows the separation of document content from content presentation.

Documents called schemas define valid tags and their containment relationships. The schema is used to verify that the XML document complies with the content model and structure dictated by the schema.

Because XML is simply text, you can use text-processing software to access the data. And because the definition follows standard rules, there are generic parsers that allow access to the internal data. As industry increasingly accepts XML as a standard (supported through W3C, the World Wide Web Consortium, www.w3c.org), XML is increasingly supported by a broad range of software platforms.

Beginning with Microsoft Visio 2002, support has been added for an XML file format that contains the same data as the Visio binary files.

For developers who use the Visio object model or program cells in the ShapeSheetwindow, the data structures will seem familiar. Most elements that define the data in the XML for Visio file are named with the same or similar names to the cells in the ShapeSheet, or the properties exposed in the object model. Because the document adheres to the XML format standard, you can use standard XSL (Extensible Stylesheet Language) or XSLT (XSL Transformations) languages for retrieving data from XML files.

The following example shows the beginning statements from an XML for Visio file, opened in Microsoft Internet Explorer.

Statements from an XML for Visio file

XML for Visio statements

The first two lines in the XML file are processing instructions:

  • The first line identifies the file as an XML file.
  • The second line is a Visio "stamp" that identifies the file as a Visio document in XML for Visio file format, and allows Visio to skip the validation of this document when you open it for editing.
  • This stamp is not required for XML documents that are created or edited outside of Visio. For details about validating XML files against the XML for Visio schema, see

  • Loading files created or edited outside of Visio.

Also notice the xmlns attribute in the VisioDocument element. This defines Visio as the default namespace, and should be included with every XML for Visio file.

Following are the three extensions for XML for Visio files:

  • .vdx for drawing files
  • .vtx for template files
  • .vsx for stencil files

Files in .vdx, .vtx, or .vsx format are designed to be peers of the Visio document binary formats—.vsd, .vst, or .vss, respectively. For example, a .vsd file can be opened and saved as a .vdx file with no loss of information.

You can use Automation interface calls to manage an XML file that is open in Visio (for example, you can open, save, export, or import XML for Visio files).

Note You can use Automation calls to manipulate objects in an XML for Visio document only while it is open in Visio. To retain changes you make through Automation, you must save the document before closing it.

Visio provides an XML vocabulary or schema that is the set of XML tags that define a Visio document's data elements and attributes and their containment relationships. Developers can refer to the schema to see how to access the data within the Visio for XML document structure.

The XML statements that follow show the top-level container, VisioDocument. This contains the DocumentProperties container, which in turn contains Title, Creator, Template and other elements.

  <VisioDocument xmlns='urn:schemas-microsoft-com:office:visio'>
...
<DocumentProperties>
<Title>VisioVDX</Title><Creator>user</Creator><Template>C:\Program Files\
Microsoft Office\Visio10\1033\Solutions\
Block Diagram\Basic Diagram (US units).vst</Template><Company>MSFT</Company>
...

For more information about the Visio XML hierarchical tag structure, see About the XML for Visio schema. For a representation of the schema itself, see XML for Visio schema. You can also download the XML for Visio schema from the Microsoft Visio Developer Center on the MSDN Web site.

Because XML for Visio is a text-based format, you can take advantage of all the text-based tools available for document management. Any text utilities for archiving, differencing, searching, indexing, or versioning can be used to process your XML for Visio files. You can:

  • Create a multifile utility to search all the text in your XML for Visio documents without running the Visio engine.
  • Index your files and search on more than just document properties.
  • Post XML for Visio files on the Web to easily share data.
  • Retrieve data embedded in the documents and run offline data processing and data analyzing applications.

Extracting data from various container level elements is relatively straightforward. For example, the following illustration shows a Visio drawing with two arrows and the text "Hello world!", the corresponding XForm section in the ShapeSheet window, and an excerpt from the resulting VDX file.

XML for Visio file format excerpt showing text position

XML for Visio file format excerpt showing text position

The "Hello world!" text in the drawing is centered at X = 3.0 inches and Y = 9.0 inches. You can see these values in the drawing view on the rulers and in the PinX and PinY cells. You can also find these values in the XML tags for the PinX and PinY elements, and the text itself after the <Text> tag highlighted in bold by Microsoft Internet Explorer. The Internet Explorer window shows a portion of the XML data created by saving the drawing in XML for Visio drawing file format (.vdx).

Note To view and edit the XML text of an XML for Visio file, open a VDX file in Notepad or in an XML editing tool.

Indents are disabled by default in VDX files to reduce file size. To enable indents for XML for Visio file output, see the section about white space in Round-tripping XML for Visio files.

To view a VDX file in Internet Explorer (version 5.0 or later), you change the file extension from ".vdx" to ".xml" and then open the file in Internet Explorer. However, you need to change the file extension back to .vdx if you want to open the file again in Visio.

For complete information about traversing the XML for Visio tag structure, see About the XML for Visio schema.

When you save a Visio document in XML file format, the first line in the XML document (<?xml version='1.0' encoding='utf-8' ?>) is a processing instruction that identifies the document as XML. The second line (resembling the following: <?integrity app='Visio' version='10.0' buildnum='2109' metric='0' key='AC376398EC7A6...' keystart='250'?>) is a processing instruction that identifies whether the document has changed since it was saved by Visio. A processing instruction (or "stamp") that indicates the document hasn't been edited outside of Visio allows Visio to skip the document validation when you open it in Visio. (The second line is only present in files that have been saved by Visio.) These files are called trusted files.

Third parties can also create and edit XML files outside of Visio that follow the Visio schema. These files are called untrusted files. If an untrusted file does not carry the stamp or the file carries a stamp that indicates the file has been modified outside of Visio, Visio checks that the XML is well-formed and valid, which can increase the time an untrusted file takes to open. If you then save the file in Visio as an XML for Visio document, the file will then contain a stamp that indicates the document is a trusted file.

For more details about working with untrusted files, see Loading files created or edited outside of Visio.

Opening a Visio document, saving it as an XML for Visio document, and then reopening the XML for Visio document shows that you can round-trip all the Visio data in the document. That is, no information is lost between the binary version and the XML for Visio version of the document.

XML files that are created or edited outside of Visio, and then opened and resaved in Visio, do not necessarily appear identical but the information should be close to identical. For example, white space is not preserved by default (except within Text elements), and some elements might get reordered (or added in some cases) in the file in a way that is preferred by Visio.

For more details about some of the XML for Visio file differences that may occur in round-tripping, see Round-tripping XML for Visio files.

You can include custom XML data within your XML for Visio file, provided the data contains well-formed XML that complies with the XML for Visio schema and the internal rules of Visio.

You can embed custom XML in an XML for Visio file in two ways:

  • As unknown XML, which is XML that Visio does not understand, but will round-trip in an XML for Visio file when contained in particular elements.
  • As solution XML, which is well-formed XML contained within a SolutionXML element that provides a standardized means of persisting solution data.
  • At the document level you can store XML data using the
  • SolutionXML
  • element contained immediately within the
  • VisioDocument
  • element. At the cell level, you can store well-formed XML data in selected cells using a string value within a
  • SolutionXML
  • element. You can then manipulate the XML data in your solution at run time through Automation.

For information about embedding and extracting application-specific data placed in drawings, stencils, or templates by a third-party solution provider, see Embedding custom XML in an XML for Visio file.

You can work with XML in Visio using a variety of tools and information, including the following resources:

  • To parse XML text and retrieve the data within the tags, you can use the Microsoft Document Object Model (DOM) or Simple API for XML (SAX) provided with Microsoft's 3.0 XML Parser library (msXML3.dll). MSXML 3.0 can be downloaded from the XML Developer Center.
  • The languages related to XSL (Extensible StyleSheet Language) and XSLT (XSL Transformations) enable you to display or further process the data, including creating other HTML or XML documents.
  • For information about working with XML as a solution across Microsoft Office XP products, see the Microsoft Office XP Developer's Guide, Chapter 10, Working with XML.
  • For XML tools for the developer, see MSDN.