3 4
Beginning with Microsoft Visio 2002, you can save Microsoft Visio drawings, stencils, and templates as XML (Extensible Markup Language) files and open them again in Visio without any loss of information. You can also include XML data from other applications within your XML data in Visio, provided the data contains well-formed XML that complies with the XML schema in Visio and the internal rules of Visio.
In a document, you can store and retrieve your solution data in XML through Automation. In a cell, you can store and retrieve your XML data as you would any other string value using the ShapeSheet spreadsheet or Automation.
Note
For more details on the XML file format in Visio and how to work with the XML schema in Visio, see the XML for Visio Reference in the Microsoft Visio Developer Center on the MSDN Web site (msdn.microsoft.com/visio/).
You can store and retrieve XML data at the document level (in a VDX, VTX, or VSX file) using the SolutionXML element contained immediately within the VisioDocument element. For example:
<VisioDocument> . . . <SolutionXML Name='SomeName' xmlns:x='y'><x:MyData>Data </x:MyData></SolutionXML> . . . </VisioDocument>
A VisioDocument element can have zero or more SolutionXML elements, and each SolutionXML element must have a unique Name attribute. When you add a SolutionXML element to a Visio document, it is recommended that you use a namespace to mark non-Visio elements.
To access the SolutionXML element in a document at run time, you can use the SolutionXMLElement, SolutionXMLElementCount, SolutionXMLElementExists, and SolutionXMLElementName properties and the DeleteSolutionXMLElement method.
For example, you can create SolutionXML elements through Automation using code similar to the following:
docObj.SolutionXMLElement("SomeName") = _ "<SolutionXML Name='SomeName' xmlns:x='y'> _ <x:MyData>Data</x:MyData></SolutionXML>"
The string passed to the SolutionXMLElement property must match the Name attribute specified in the SolutionXML element.
For more details on the SolutionXMLElement, SolutionXMLElementCount, SolutionXMLElementExists, and SolutionXMLElementName properties and the DeleteSolutionXMLElement method, see the Microsoft Visio Developer Reference (on the Help menu, click Developer Reference).
For more details on the XML file format in Visio and how to work with the XML schema in Visio, see the XML for Visio Reference in the Microsoft Visio Developer Center on the MSDN Web site (msdn.microsoft.com/visio/).
You store XML data in cells using a string value within a SolutionXML element. Only A, B, C, or D cells in the Scratch section, or Value cells in the User-Defined Cells or Custom Properties sections of the ShapeSheet spreadsheet can accept XML data, and the XML must be well-formed.
When you work with XML data in cells through the ShapeSheet spreadsheet or Automation, you can retrieve your XML data as you would any string value in a cell.
Unlike document-level XML, SolutionXML elements maintained in a cell do not require a Name attribute. (In a cell, there are no uniqueness semantics for SolutionXML elements that use a Name attribute.) However, it is recommended that you supply a namespace used to mark non-Visio elements within a SolutionXML element in a cell.
There are several legal ways that you can create a formula using the SolutionXML element. If a cell has a formula that matches one of the patterns shown here:
<SolutionXML> ... </SolutionXML>
<SolutionXML ... > ... </SolutionXML>
<SolutionXML ... />
and if the formula is well formed XML, for example:
"<SolutionXML xmlns:x='y'><x:MyData>Data</x:MyData> _ </SolutionXML>"
or
"<SolutionXML xmlns:x='y' x:MyData='Data'/>"
when the formula is saved as XML in Visio, it is saved as XML rather than as a parsed string, for example:
<User ID='2'> <Value Unit='STR'> <SolutionXML xmlns:x='y'><x:MyData>Data</x:MyData> _ </SolutionXML></Value> <Prompt>hello</Prompt> </User>
If a cell contains XML, but it is not contained within a SolutionXML element, or if the XML is not well-formed, Visio will output a string value that is not recognizable as XML. For example, the formula of a Value cell in the User-Defined Cells section might be "=<abc>" . When Visio saves such a formula in XML it will generally output a string similar to that shown here:
<User ID='2'> <Value Unit='STR'><abc></Value> <Prompt>Hello</Prompt> </User>
Note
For more details on the XML file format in Visio and how to work with the XML schema in Visio, see the XML for Visio Reference in the Microsoft Visio Developer Center on the MSDN Web site (msdn.microsoft.com/visio/).