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

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server