Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XML中缺少名称属性的某些形状_C#_Xml_Visio2013 - Fatal编程技术网

C# XML中缺少名称属性的某些形状

C# XML中缺少名称属性的某些形状,c#,xml,visio2013,C#,Xml,Visio2013,我正在尝试编写一个C应用程序,它读取.vsdx文件。下面的XML是我的一个文件中的页面。只有少数形状元素具有Name和NameU属性。有人知道这是为什么,或者如何修复吗?下面所有没有名称属性的形状元素都应该是对象生命线 <?xml version="1.0" encoding="UTF-8"?> -<PageContents xml:space="preserve" xmlns:r="http://schemas.openxmlformats.org/officeDocumen

我正在尝试编写一个C应用程序,它读取.vsdx文件。下面的XML是我的一个文件中的页面。只有少数形状元素具有Name和NameU属性。有人知道这是为什么,或者如何修复吗?下面所有没有名称属性的形状元素都应该是对象生命线

<?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">

谢谢你的回答!我应该澄清一下,这些文件是由Visio 2013创建的,我需要能够阅读在Visio中创建的软件设计文档。我发现了相同的问题-并非所有关系都有其名称U组名称,描述了关系的类型。。。
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);