This documentation is archived and is not being maintained.

XML for Visio Scenarios

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 Corporation

June 2001

Applies to:
    Microsoft Visio Standard 2002
    Microsoft Visio Professional 2002

Summary: This article illustrates how XML for Visio can be used to extract Visio data for use in solution development, data analysis, text localization, Web publication, and database interoperability. (6 printed pages)


Key Points
Using XML for Visio Documents
XML for Visio Scenarios
XML Resources


This article describes a new file format, XML for Visio, for native data in Microsoft® Visio® 2002. Extensible Markup Language (XML) is a tagged data format that is platform independent, vendor neutral, standardized by the World Wide Web Consortium (W3C), and widely available. XML is actually a metalanguage that forms the basis for other languages or vocabularies. Combined with W3C open standards and the ability to provide its own data definitions, XML is an enabling technology that provides the syntax for the expression of rich open data formats. The standard provides language and character set neutrality, unambiguous rules for white space, escape characters, extensibility, mixing of data models, and other syntactic details.

Visio 2002 has defined an XML vocabulary (schema) that expresses all the Visio drawing, template and stencil data in its internal model. The XML extension rules allow users to attach and maintain custom data to a drawing. The familiarity of XML and the availability of standard tools give applications access to the Visio model without requiring the full Visio application.

Open standards such as XML expand the opportunities and means of sharing and exchanging data. The XML for Visio scenarios in this article highlight some of the potential uses for this new format.

Key Points

If you are familiar with Visio but new to XML, the following summary will help you understand how to use the new XML for Visio format to its best advantage.

Text File Format

  • XML is an open (non-proprietary) text-based standard used widely throughout the industry.
  • XML files contain data with <Tag> and </Tag> delimiters. The Tag names are usually simple labels describing the data between the tags. For example, <Name>James Smith</Name> might be an XML tag defining someone's full name. XML tags can be nested but not overlapped.
  • Standard text tools for revision tracking, version control, search and replace, indexing, archiving, and even editing can be used on XML for Visio documents.
  • As text-based files, XML for Visio documents can be processed in batch mode or through scripts since the Visio engine is not necessary to interpret the data.

XML for Visio Format

  • All types of Visio documents (drawings, stencils, and templates) can be saved in the XML for Visio format.
  • Visio provides tag definitions for its document data in the XML for Visio schema, a separate document that lists the tags and their containment relationships. The schema generally follows the Visio object model and has predefined places for customized tags, which solution providers can use for preserving custom data.
  • Solution providers can extract any XML data from the Visio documents for external processing by using existing XML tools, and then modify that data or create new drawings to display the results.
  • Solution providers can extract customized shape definitions from the Masters section of the XML for Visio tag hierarchy. These shapes can then be shared, modified, or included in their custom solutions.
  • Solution providers may be able to convert drawings to and from other drawing file formats using the XML for Visio schema, and by using XML as an import/export file format.

XML Tools and Applications

  • Many tools and applications support XML. For example, XML is now accepted as a data source supported by Microsoft® ActiveX® Data Objects Plus (ADO+). This powerful alternative expression of Visio drawing data also enables the use of database tools like queries, locking, and versioning.
  • Existing XML parsers, including the Microsoft® XML Parser (MSXML), enable you to manipulate the data elements within an XML document. The XML Document Object Model (DOM) style of parsing reads the entire document into memory and allows you to extract or modify elements within the document. With Simple API for XML version 2 (SAX2), an events-based parser that streams document data, you can retrieve data from very large documents without the overhead of reading them into memory first.
  • In addition to XML parsers, the Extensible Stylesheet Language (XSL) script provides a way to easily extract data from an XML document.
  • Microsoft® Internet Explorer 5.0 uses the XML DOM and provides a way to view XML documents. You can expand and collapse the nodes of the XML tag hierarchy interactively just as you can expand and collapse nodes of a directory structure.

XML and the Web

  • Web-based applications often include creative elements. By accessing Visio data through the XML for Visio file format, solution providers have more opportunities to share, display, and customize Visio data than when it was in a proprietary format.
  • XML snippets can exist in specially marked sections of Web pages so that data can be readily shared.
  • Other support for Web-based sharing of Visio documents includes the menu item Save as Web Page and support for Web-style graphic formats, such as GIF, JPG, or PNG.

Using XML for Visio Documents

Managing the increasing number of electronic documents that pass through our daily lives—as well as extracting data from them—is a daunting task. An open format such as XML allows us to programmatically extract data from many sources and recombine it in ways that help us work more efficiently, have greater insight into our data, and communicate that information more successfully to our audience.

Visio data can now be extracted with the XML for Visio file format. The following table describes various scenarios that reflect the flexibility and range of applications that may benefit from this new data accessibility.

XML for Visio Scenarios

Extracting Data and Viewing on the Department Web PageJoe is a secretary and one of his projects is to create a new phone list each week for his rapidly growing company. His manager likes to have a copy of the most recent org chart accompanied by a phone list so she can greet newcomers personally. Joe uses the Org Chart Wizard in Visio 2002 to keep his chart up-to-date.

He asks the corporate developer to help him find a way to create a phone tree each time he updates the org chart. Using the XML for Visio file format and a simple Extensible Stylesheet Language (XSL) script to extract the names and phone numbers, the developer provides a one-click solution that creates the phone list as a Hypertext Markup Language (HTML) page on their intranet.

HTML Reporting in Microsoft Internet Explorer 5.0An Information Systems manager wants a summary of all her network equipment. She has created a number of XML for Visio drawings that represent her department's network. She creates a small Visual Basic Script Edition (VBScript) program and an XSL script to create a report of the network equipment.

When she runs the script, it searches a drive for *.VDX files. When the script finds a VDX, it applies the XSL to the VDX and appends the result to an HTML file. The XSL parses the VDX looking for custom properties that pertain to network equipment. The script creates a new HTML document containing a concise report of the manager's network equipment.

End User XML Data PersistenceTed is a process engineer who uses Visio to develop Piping and Instrumentation Diagram (P&ID) drawings. He also uses a specialized Web site to identify valves that can be ordered from approved manufacturers for the pipelines he designs. The Web site's valve locator provides XML data describing the valve. This data includes: valve type, manufacturer, model, pipeline size, flow capacity, and pressure drop. Ted associates the manufacturer information with the valve shapes in his Visio drawing through a Microsoft® Visual Basic® for Applications (VBA) macro that opens the file and adds custom property rows that contain data derived from the XML data provided by the manufacturer. This data is saved in the drawing and is included in customized reporting programs that extract that data from the XML for Visio drawing.
Storing Custom Data in a Visio DocumentNancy has been a long-time user of Visio drawings. In the past, she has placed her persistent data in a hidden shape in each of her drawings. When she shares her drawings with others in the company, she needs to indicate which macro to run to make the shape visible so they can see the extra data.

In the XML for Visio format, Nancy realizes she can save persistent data as SolutionXML data in the document level of the XML tag hierarchy. In addition, she sees that she can define a template for the XML data and create a prompt for that element, ensuring that each use of the template includes entering the customized data. When her fellow workers now use her drawing templates, Visio prompts them for the extra data needed in a uniform, consistent manner.

Database InteroperabilityGeorge's company has an exciting new contract with an international firm. The company's first project is to exchange its most recent lab procedures and results to make sure each lab understands the latest data. George's lab uses Visio drawings to document their procedures, and then embeds setup data and results into the XML for Visio drawings.

The other lab does not use Visio. However, it frequently uses its SQL server for analyzing its own data results.

George decides to use a combination of the XML Document Object Model and OPENXML (a Transact-SQL keyword that provides a rowset over in-memory XML documents) to extract the information from his Visio documents in the same format the other lab uses from their SQL database. In this way, comparisons between data from the two labs are provided in a uniform, language-independent way.

Developer ToolsShawn is a solution provider working on proprietary documents. He is providing a customized indexing interface to an existing indexer. He only wants specific XML tagged data indexed for his proprietary Visio drawings and not any of the rest of the information. He has been successful at indexing his customized XML tags, but is also getting hits on text that he knows is nested deep in a Visio shape.

Shawn isolates the shape causing the problem, places it alone in a new Visio drawing, recreates the problem, and saves the drawing in XML for Visio format. Loading this file into Internet Explorer 5.0, he uses the expand/collapse flags on the XML tag hierarchy to understand the internal structure of this shape. He quickly determines the nesting rules for the text in question and edits his code to eliminate them from the indexer.

Customizing Keywords for Indexing DocumentsLinda is a Document Management Librarian assigned to archive and index all of the documents in her company. The company keeps a set of internal Web servers where the documents reside. Documents are archived to permanent storage on an ongoing basis. Their indexing software already supports XML documents.

Up until now, she could only search the document properties fields associated with her Visio drawings. By converting the Visio drawings to XML for Visio format, Jane ensures that standard XML indexers catalog text data within each document. In addition, she tailors the conversion process with a VBA macro to include customized XML comment fields within her documents as well as other data of interest to the company. Her searches now include hits on both text within the Visio document and the Visio document properties.

Revision Tracking and Version ControlJane's job is to track drawing revisions in her company. By saving Visio drawings, templates, and stencils as XML for Visio documents, she can use XML revision control and differencing engines to track changes in the company's drawings.
Web AccessJohn saves his Visio 2002 drawing as XML for Visio so that the data is accessible to the XSL and other XML search and transform-based tools that the project Web site uses for reporting purposes. Daily reports created from the project Web now include his latest work.

XML Resources

  • XML Reference for Microsoft Visio includes the XML for Visio schema, a complete element reference, and information about working with XML. Read more about this in XML Reference for Microsoft Visio .
  • XML Developer Center has the latest information on XML including the XML SDK, code samples, downloads, and technical articles.