Partager via


Dev Luv: Storing Custom XML in Visio XML File Format

The Visio XML file format, as discussed earlier, is a physical file format with all the information that Visio needs to render the diagram with the same fidelity as the binary file format. Let’s consider the case in which a developer wants to use the data stored in shapes in a Visio business process diagram. Each process shape has information about status, owner, due dates, and a notes description. The geometry of the shapes isn’t important to the developer, since the developer just wants to take the shape data and update a database or a server-side component that manages workflow shape information.

 

In this scenario, the developer can write a transform of VDX to that XML schema. This can be a little work or a lot of work, depending on the target XML schema. But if the developer only cares about the shape data and potentially some shape relationship information (like other connected shapes), I’d recommend using SolutionXML.

 

Visio introduced SolutionXML in Visio 2002. SolutionXML is well-formed XML contained within a SolutionXML element that provides a standardized means of persisting solution data. You can store SolutionXML at the Document level, where it is stored immediately in the VisioDocument element. Typically, this is the easiest way to store and retrieve SolutionXML.

 

The Visio 2003 SDK’s Code Librarian has a sample that how to set and retrieve SolutionXML at the Document and Cell level in VB.NET, VB, and C#. In Code Librarian, look in the Integration section to find the “Data Storage in SolutionXML” class. There’s a couple of helper methods for conversion of formula to string, and string to formula that you’ll need too. Here’s a link to the C# class that puts and gets XML data for both documents and cells.

Here’s how it would work. Let’s say that your user updates the status information in a custom property in the process diagram. On Document Close, CellChanged, ShapeDrop, or some other event, you can wrap SolutionXML around the data that you care about and store that SolutionXML at the Document level. (Although namespace definition is optional for SolutionXML, I’d recommend that you use it.)

 

SolutionXML injected into your Visio XML document looks something like this:

- <SolutionXML>

- <o:TREENODE xmlns:o="**https://www.someURL.com/somenamespace**" fullname="Snow White" emailname="snowwhite" standardtitle="Princess" building="castle" room="master bedroom" workphone=" +1 (111) 111-1111">

Snow White (Princess)

<o:TREENODE fullname="Grumpy" emailname="grumpy" standardtitle="Dwarf" building="cottage" room="2" workphone=" +1 (222) 222-2222">Grumpy (Dwarf) </o:TREENODE>

<o:TREENODE fullname="Doc" emailname="doc" standardtitle="Dwarf" building="cottage" room="3" workphone=" +1 (222) 222-2222">Doc (Dwarf) </o:TREENODE>

</o:TREENODE>

</SolutionXML>

 

You can then write a separate parser that cracks open the Visio XML document, extracts the SolutionXML, and writes it a separate smaller file or into a database. This approach has the following benefits:

  • Customize Visio's XML: You can inject your own well-formed XML into the Visio XML file format, and wrap the data that you want to reuse in another part of your system.
  • Easier extraction: It's alot easier to extract your custom XML when you parse for the <SolutionXML> tag and/or namespace.
  • Smaller XML files: If you can extract the XML you care about, you end up working with MUCH smaller XML files than working with the entire Visio document.

-- Mai-lan

 

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

Comments