automating conversion from visio files to xml

Z

ZeroVisio

Hi,

I'm a complete newbie to the world of visio and .net. I'm trying to figure
out how if and how I can use visio sdk with C#. If it is possible to use
these two together, then what kind of code do I need to write to convert
visio diagrams into XML?
My ultimate goal is to develop an application that would take visio file as
an input and identify what shapes are there and how they are connected to
each other and write this whole thing to a text file or a ACCESS database. I
hope my question makes sense... any help would be greatly appreciated.
 
S

shashi behari

Yes it's very possible to do, in fact.. i've almost completed a component to
do exactly this.

the Visio SDK is a vital reference for C# Automation because quite honestly
there is a lack of documentation for this (the MSDN isn't helpful at all).

i suggest if you want to start out get the SDK, it comes with something
called the Code Librarian which has sample code on how you would automate
Visio functions with C#.

from there you should be able to figure out how to get the shapes on a page,
see how they are connected, etc. and programmatically build your XML file
with .NET"s XMLDocument class or something similar.

i don't think you would be able to use a visio diagram as input for another
application without using an instance of visio itself, so you could look into
using either an Add-In (a .dll which runs in the visio process) or you could
control visio from your own application.

As far as data goes, you have the option of using a Shape's Custom
Properties to store just about anything (with a limited Type set though)
Visio also allows you to inject your own XML elements into a diagram (called
SolutionXML).

something i've discovered about converting from visio to XML, though, is
that it is very slow depending on how complex your diagram and shapes are,
and how much data you need to extract from them.

Good Luck
 
Z

ZeroVisio

Hi Shashi,

Thanks for the info. It is very helpful. I have downloaded Visio 2003 SDK
and will look at the sample code.

Actually for last couple of days, i have been studying the xml output from
visio (the one you get when you save the visio drawing as XML drawing). from
scanning that xml output it appeared that i needed to write xml parser or
something like that..
do you know if there exists something like document.saveas (filetype)?
 
S

shashi behari

You can use the Document.SaveAs("doc.vdx") method, it just worked when i
tried . there is also SaveAsEx(".vdx", saveFlag).

Since you're using C# you can use the XMLDocument class and just look for
the elements you need, parsing each xml node in a vdx document with the
XMLReader would probably take forever (for some reason a visio exported XML
file is far bigger than just a normal visio doc)
 
Z

ZeroVisio

Hi Shashi,

thanks for your previous comments. I actually figured I wont need to convert
to XML but can directly access the shapes from visio. In this process I'm
getting another error during compilation. Error is as follows:

***************
An unhandled exception of type 'System.NullReferenceException'
occurred
Additional information: Object reference not set to an instance
of an object.
*********************

I checked one fix post on the same, but didnt have much success.

Any help would be greatly appreciated.
 
Z

ZeroVisio

Ooops, sorry ignore this posting. I think my partner already posted this
elsewhere to whhich you had replied... sorry about the trouble..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top