Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
programming4us
Windows 7

Microsoft Visio 2010 : Exporting rule sets to XML

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
3/30/2012 11:27:00 AM
Even though there is an option to import a rule set from another Visio document, I know that some rules developers would like to export and import rule sets to XML. This allows rule sets to be stored, restored, and analyzed more easily.

I decided that the XML structure exported should mimic the Visio XML format, and thus use a part of the Visio XML schema. This means using the same namespaces, but it would mean that any XSL stylesheets developed for our export would also work for the standard Visio XML format (*.vdx and *.vtx files).

I decided to include the option to export the issues in a document too, because someone may have the need to use them in an external program. Having the issues available in XML format means that they could be displayed as a table, for example, so that they can be reviewed independently.

The ExportDocument() method first constructs a title for SaveFile dialog, depending upon the include options provided. The default name preferred for the XML file uses the drawing file name as a base.

Once a file name has been obtained, the System.XMl.Linq.XDocument object is created; saved and opened in the associated application.

public void ExportDocument(bool includeRulesets, bool includeIssues)
{
try
{
//Set the title for the SaveFile dialog
string title = "";
if (includeRulesets) title += "RuleSets";
if (includeRulesets && includeIssues) title += " and ";
if (includeIssues) title += "Issues";
string shortName = System.IO.Path.GetFileNameWithoutExtension( this.document.FullName);
string fileName = System.IO.Path.Combine(this.document.Path, shortName + ".xml");
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.Title = "Save " + title;
dlg.InitialDirectory = System.Environment.GetFolderPath( System.Environment.SpecialFolder.MyDocuments);
dlg.FileName = shortName + " " + title + ".xml";
dlg.OverwritePrompt = true;
dlg.DefaultExt = ".xml";
dlg.Filter = "XML documents (.xml)|*.xml";
if (dlg.ShowDialog() == true)
{
fileName = dlg.FileName;
}
else return;
XDocument xDoc = getXDocument(includeRulesets, includeIssues);
if (xDoc != null)
rules setsexporting, to XML{
//Save the file
xDoc.Save(fileName);
//Open the file with the associated program
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(fileName);
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
System.Diagnostics.Process.Start(startInfo);
}
Visio diagrams, annotatingrule sets, exporting to XML}
catch (Exception)
{
throw;
}
}


					  

Getting the XDocument object

The following method first creates the required XNamespace objects, then it creates a new XDocument object and retrieves the XElement objects for the VERules and/or VEIssues of the VEDocument.

private XDocument getXDocument(bool includeRulesets, bool includeIssues)
{
try
{
//v14:Validation
// v14:ValidationPoperties
// LastValidated
// ShowIgnored
// v14:RuleSets
// v14:RuleSet
// ID
// NameU
// Description
// v14:Rule
// ID
// NameU
// Category
// Description
// v14:RuleFilter
// v14:RuleTest
// v14:Issues
// v14:Issue
// ID
// v14:IssueTarget
// PageID
// ShapeID
// v14:RuleInfo
// RuleSetID
// RuleID
XNamespace xns = "http://schemas.microsoft.com/visio/2003/core";
rule sets, exporting to XMLXDocument object, obtainingXNamespace v14 = "http://schemas.microsoft.com/office/visio/2009/5/extension";
XNamespace vx = "http://schemas.microsoft.com/visio/2006/extension";
XDocument xdoc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Exported from Rules Tools " + this.document.Name + " on " + System.DateTime.Now.ToUniversalTime().ToString()),
new XElement(xns + "VisioDocument", new XAttribute(XNamespace.Xmlns + "vx", vx.NamespaceName), 
new XAttribute(XNamespace.Xmlns + "v14", v14.NamespaceName), new XElement(v14 + "Validation"))); XElement validNode = xdoc.Element(xns + "VisioDocument").Element(v14 + "Validation"); if (includeRulesets) { if (this.SelectedVERuleSet == null) { validNode.Add(new XElement(v14 + "RuleSets", from el in this.VERuleSets select el.GetXElement(v14) )); } else { validNode.Add(new XElement(v14 + "RuleSets", from el in this.VERuleSets where (el.ID == this.selectedVERuleSet.ID) select el.GetXElement(v14) )); rule sets, exporting to XMLXDocument object, obtaining} } if (includeIssues) { validNode.Add(new XElement(v14 + "Issues", from el in this.VEIssues select el.GetXElement(v14) )); } return xdoc; } catch (Exception) { } return null; }

Getting the VERuleSet XElement

The following method creates an XElement for the VERuleSet object, and then adds an XElement for each VERule in the VERules collection.

public XElement GetXElement(XNamespace v14)
{
XElement retNode;
try
{
retNode = new XElement(v14 + "RuleSet",
new XAttribute("ID", this.ID),
new XAttribute("NameU", this.NameU),
new XAttribute("Name", this.Name),
new XAttribute("Description", this.Description));
retNode.Add(from ver in this.VERules select ver.GetXElement(v14));
}
catch (Exception)
{
throw;
}
return retNode;
}


Getting the VEIssue XElement

This method creates an XElement for the VEIssue object, and then adds an XElement for the RuleInfo and IssueTarget.

public XElement GetXElement(XNamespace v14)
{
XElement retNode;
try
{
retNode = new XElement(v14 + "Issue", new XAttribute("ID", this.ID),
new XElement(v14 + "RuleInfo", new XAttribute("RuleSet",this.Rule.RuleSet.ID), new XAttribute("Rule", this.Rule.ID)));
if (this.Ignored)
{
retNode.Add(new XAttribute("Ignored", this.Ignored));
}
if (this.TargetPage != null || this.TargetShape != null)
{
XElement targetNode = new XElement(v14 + "IssueTarget");
if (this.TargetPage != null)
targetNode.Add(new XAttribute("PageID", this.TargetPage.ID));
if (this.TargetShape != null)
targetNode.Add(new XAttribute("ShapeID", this.TargetShape.ID));
retNode.Add(targetNode);
}
}
catch (Exception)
{
throw;
}
return retNode;
}					  
Other -----------------
- Microsoft Access 2010 : Editing a Query in Design View
- Microsoft Access 2010 : Copying to and from Other Office Programs
- Microsoft Excel 2010 : Refreshing Pivot Table Data, Adding a Report Filter & Adding Pivot Table Data
- Microsoft Excel 2010 : Creating a Pivot Table & Rearranging a Pivot Table
- Windows 7 : Virtualization (part 2) - Native Hard Disk Support in Windows 7
- Windows 7 : Virtualization (part 1)
- Microsoft Project 2010 : Putting a Price Tag on Your Project & Incorporating Resource Costs
- Customizing Project 2010 : Creating and Editing Views
- Microsoft Outlook 2010 : Processing Messages Automatically - Controlling Rules & Sharing Rules with Others
- Microsoft Outlook 2010 : Processing Messages Automatically - Creating and Using Rules
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Trailers Game
- The Banner Saga 2 [PS4/XOne/PC] PC Launch Trailer
- Welkin Road [PC] Early Access Trailer
- 7th Dragon III Code: VFD [3DS] Character Creation Trailer
- Human: Fall Flat [PS4/XOne/PC] Coming Soon Trailer
- Battlefleet Gothic: Armada [PC] Eldar Trailer
- Neon Chrome [PS4/XOne/PC] PC Release Date Trailer
- Rocketbirds 2: Evolution [Vita/PS4] Launch Trailer
- Battleborn [PS4/XOne/PC] 12 Min Gameplay Trailer
- 7 Days to Die [PS4/XOne/PC] Console Trailer
- Total War: Warhammer [PC] The Empire vs Chaos Warriors Gameplay Trailer
- Umbrella Corps [PS4/PC] Mercenary Customization Trailer
- Niten [PC] Debut Trailer
- Stellaris [PC] Aiming for the Stars - Dev. Diary Trailer #1
- LawBreakers [PC] Dev Diary #4: Concept Art Evolutions
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer