Solved

Generating mind map from xml fields

Posted on 2007-11-16
6
706 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

627 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