Condividi tramite


Dev Luv: Visio’s XML File Format

Visio has a native XML file format for a Visio drawing, a Visio template, and a Visio stencil. We do not have the ability to save a Visio drawing into any other XML schema but our own (and SVG, if you are using Visio 2003). If users want Visio diagrams in BPEL or some other business XML format, the user needs to work with a solution provider or their IT department to write an XLST to transform the Visio XML file format to another schema. I’ll blog more about transforms later on this week. First, I wanted to give a little bit of background on the Visio XML file format itself.

 

You can save any Visio diagram into XML format using File | Save As and open it in an XML editor to read. Once you’ve loaded a Visio XML document into an XML editor, you will note right away that a) the schema is quite complex and b) the XML file itself is relatively large compared to its VSD format, and c) it’s a great way to learn about the Visio automation model and/or what comprises a Visio shape.

 

That’s because Visio’s XML file format is a physical file format. In order to render the Visio drawing properly from XML, Visio needs the document schema to tell the app all the gory details about geometry, layout, and other behaviors for the shape. Consider the following simple flowchart.

 

 

If you save out this drawing into a VDX file, you will get a 135 KB XML file. (It’s 44 KB in Visio’s binary drawing format.) If you click here, you can take a look at the XML. About 20% of this file is garbage because by default, when you save a Visio file, it saves with the Preview Picture option turned on in Document Properties. Once I go and turn off the Preview option (on the File | Properties dialog, look on the Summary tab and uncheck Save Preview Picture checkbox), the file size for the document reduces to 107 KB. Click here for the XML without Preview Picture garbage.

 

The good news is that the Visio XML schema is documented as part of the Office 2003 XML Reference Schemas. The bad news is that Visio XML can be clumsy for developers to extract specific information, like Shape text or Shape custom properties, from the document.

 

In Visio 2002, Visio introduced SolutionXML, which is customer-defined XML that developers can store at the document or cell level and retrieve by a custom (optional) namespace.

 

Later on this week, I will cover how to use SolutionXML, which is what I would recommend to developers to store custom data that they want to pull out of the Visio XML file format with minimal parsing.

 

For today’s XML topic, the key takeaways are:

  • You can save a document, stencil, or template into Visio’s XML file format. Visio does not have native support for saving a Visio document into any other XML file format than its own and SVG. To convert a Visio XML document to another XML file format, a developer needs to write an XSLT. (to be covered later this week in my blog)
  • Always turn off Preview Picture when saving to XML file format to reduce the size of your Visio XML file.
  • If you plan to generate a lot of Visio XML files automatically, you might want to make sure that you have space for it on your file share. The files can get quite large.
  • Developers should not have to walk the entire schema in a Visio XML file if all you want out of the file is shape-specific data. There’s a better alternative called Visio SolutionXML. (to be covered later this week in my blog)

 -- Mai-lan

 

This posting is provided "AS IS" with no warranties, and confers no rights

Comments

  • Anonymous
    November 11, 2004
    Hello Mai,
    I'm posting these questions because I've almost fried my brain looking for the answers, with no success so far!
    Before XML, I used to create a text file, which I would then open in Visio through the wizard, and my flow was displayed with all shapes automatically placed in the page.
    I'm now entering the world of Visio XML files and so far I couldn't find a way to do the same in the XML! Do you know how can I:
    - create an XML file, without setting shapes position, letting Visio automatically place the shapes for me?
    - create an XML file, without setting the connectors positions, simply specifiying "connect shape A to shape B", letting Visio take care of the drawing for me?
    Thanks.
  • Anonymous
    November 11, 2004
    Hi, Joao: I checked with Dan, our local XML guru, and you can do this, but with a little bit of work. You'll need to add some VBA to handle it on document open and call Layout.

    Using the Connect element you can specify the connector relationships by shape ID (and connection position). Check out the following:


    <Shape ID='3' NameU='Dynamic connector' Type='Shape' Master='0'/>

    </Shapes>

    <Connects>

    <Connect FromSheet='3' FromCell='BeginX' FromPart='9' ToSheet='1' ToCell='PinX' ToPart='3'/>

    <Connect FromSheet='3' FromCell='EndX' FromPart='12' ToSheet='2' ToCell='PinX' ToPart='3'/>

    </Connects>



    This XML snippet will instance a “dynamic connector” (pick your favorite connector master) and dynamically glue it to the shapes in question (see the GlueTo API for how this all works).


    -- Mai-lan