1

I am trying to write a C# app which reads in a .vsdx file. The XML below is the page from one of my files. Only a few Shape elements have a Name and NameU attribute. Does anyone know why this is or how it can be fixed? All of the Shape elements below which do not have Name attributes should be Object lifelines.

<?xml version="1.0" encoding="UTF-8"?>
-<PageContents xml:space="preserve" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.microsoft.com/office/visio/2012/main">
-<Shapes>
+<Shape Master="7" Type="Group" Name="Object lifeline" NameU="Object lifeline" ID="1">
+<Shape Master="7" Type="Group" ID="6">
+<Shape Master="7" Type="Group" ID="11">
+<Shape Master="7" Type="Group" ID="16">
+<Shape Master="7" Type="Group" ID="21">
+<Shape Master="7" Type="Group" ID="26">
+<Shape Master="7" Type="Group" ID="31">
+<Shape Master="8" Type="Shape" Name="Message" NameU="Message" ID="36">
+<Shape Master="8" Type="Shape" ID="37">
+<Shape Master="9" Type="Shape" Name="Return Message" NameU="Return Message" ID="38">
+<Shape Master="7" Type="Group" Name="Object lifeline.39" NameU="Object lifeline.39" ID="39">
+<Shape Master="7" Type="Group" Name="Object lifeline.44" NameU="Object lifeline.44" ID="44">
+<Shape Master="8" Type="Shape" ID="49">
+<Shape Master="8" Type="Shape" ID="51">
+<Shape Master="9" Type="Shape" ID="52">
+<Shape Master="11" Type="Shape" Name="Activation" NameU="Activation" ID="53">
+<Shape Master="8" Type="Shape" ID="54">
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Maddie Lowe
  • 73
  • 1
  • 5
  • I'm observing the same problem - not all relationships have their `NameU` group name, describing the type of the relationship... – BartoszKP Feb 22 '18 at 17:48

1 Answers1

0
var xDoc = XDocument.Load(path);
var elements = (from e in xDoc.Descendants("Shape")
                    where (string)e.Attribute("Name") == null
                      select e).ToList();
foreach (var item in elements)
{
    item.Add(new XAttribute("Name", "Object lifeline");
}
xDoc.Save(path);
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • Thank you for your answer! I should have clarified though that these files are created by Visio 2013, and I need to be able to read in software design documents created in Visio. – Maddie Lowe Jan 08 '14 at 15:43