Storing and Retrieving XML Data in Your Solutions

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


The three XML file formats in Visio correspond to the three types of Visio files: XML drawing files have the .vdx file name extension; XML template files have the .vtx file name extension; and XML stencil files have the .vsx file name extension. These files function in the same way as their binary counterparts (.vsd, .vst, and .vss, respectively).

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/).

Storing XML Data in and Retrieving XML Data from a Document

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/).

Storing XML Data in and Retrieving XML Data from a Cell

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'>&lt;abc&gt;</Value>       <Prompt>Hello</Prompt> </User> 

Note


Visio treats cells with SolutionXML elements differently from other cells only when a document is saved in XML file format. When you work with XML data in cells through the ShapeSheet spreadsheet or Automation, you can store and retrieve your XML data as you would any string value in a cell.

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/).



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net