Solved

Generating mind map from xml fields

Posted on 2007-11-16
6
704 Views
Last Modified: 2008-02-01
I would like to do this for directories within a directory:

(1) Open an xml file X
(2) Read a name field from X to a string
(3) Put a circle with that name on a visio sheet

Thanks

Andy
0
Comment
Question by:mranders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 20297390
if visio has a COM Interface this is not that hard.
1) check that you have some XML library like msxml or libxml2 installed
 1.1) do whatever is needed to open the xml file
2) use an XPath search string to look for the pattern you're interested in
3) Open the COM interface of visio
4) find the proper function to call in the COM interface.

Not difficult if you know XML, and COM programming otherwise....

Regards
Friedrich
0
 

Author Comment

by:mranders
ID: 20298085
Thanks Fridom. I was hoping that someone had done something simiilar and could provide some sort of code snippet  as a starting point.
0
 
LVL 30

Expert Comment

by:Scott Helmers
ID: 20303163
Andy,

The Visio macro recorder is a great way to generate sample code. For example, I turned on the macro recorder, drew a circle (by using the Drawing toolbar), then double-clicked on it and added text.  After I stopped the recorder, I only made one edit -- I set the x/y parameters for the DrawOval method to integer values for convenience. (BTW, the first two numbers are the x and y coordinates of the lower left corner of the width-height box surrounding the circle; the second pair of numbers is the upper right corner.)

If you paste the attached code into the VBA editor and run it, you'll have a circle on the page containing text.

Obviously I've skipped over your requirement to read data from an XML file but let me know if this much is useful to start.

Sub DrawCircle()
 
    Application.ActiveWindow.Page.DrawOval 3, 4, 4, 5
 
    Dim vsoCharacters1 As Visio.Characters
    Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).Characters
    vsoCharacters1.Begin = 0
    vsoCharacters1.End = 0
    vsoCharacters1.Text = "text in circle"
 
End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mranders
ID: 20303461
Scott,
Thanks, you suggestion could be the way to go - to work with the macro recorder and do as much as you can with it, then try to figure out how to go through the subdierectories in a folder open an xml file within each, search within that file for the right tag etc. I suspect this latter part is not trivial however.
0
 
LVL 30

Accepted Solution

by:
Scott Helmers earned 500 total points
ID: 20304478
Andy,

After I posted last night I had a nagging feeling that I'd seen sample VBA code for looping through multiple files in a directory. I found it this morning on a long-time Visio help site. The specific page of VBA samples is here: http://visio.mvps.org/VBA.htm but be sure to browse the rest of the site as well. It looks like most of the information here is circa Visio 2003 or earlier but the basics of Visio VBA haven't changed -- you just won't find code snippets that use newer Visio functions.

The sample below specifically looks for Visio files but shouldn't be hard to adapt to find XML files instead. As far as locating specific data inside an XML file, that's just basic text parsing because an XML file is straight text. I'm sure the VB zone or VB support sites should be able to help with the text processing piece as that really doesn't have anything to do with Visio.

LoopThroughFiles: This subroutine loops through the files in a specific directory.
 
Sub LoopThroughFiles()
' This program will loop through specific files within a directory.
 
Dim docsObj As Visio.Documents, docObj As Visio.Document, pagsObj as Visio.Pages
Dim PathFileName As String, PathName As String, CurrFileName As String
 
' Set the default pathname
PathName = "C:\VisioTemp\"
PathFileName = PathName & "*.vsd"
 
' Find the first file from the directory (not necessarily the first alphabetically)
CurrFileName = Dir(PathFileName)
 
Do While CurrFileName <> ""
 
' Open the file
PathFileName = PathName & CurrFileName
Set docObj = Documents.Open(PathFileName)
Set pagsObj = docObj.Pages
 
 
 
' Do what you want to the pages in this file!
 
 
docObj.Save
docObj.Close
 
CurrFileName = Dir
Loop
 
End Sub

Open in new window

0
 

Author Comment

by:mranders
ID: 20333560
Thanks Scott I have some good ideas now to get started.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question