Solved

Generating mind map from xml fields

Posted on 2007-11-16
6
699 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
  • 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 57
strCopies  challenge 17 73
python sqlite question 11 43
Adding Namespace to the second node of the xml 16 33
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now