以下是我目前使用的(简化)XML:
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="242.359" height="557.669" id="svg2" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(71.9446563720703,1057.6692276001)">
<!--nodes-->
<polygon stroke="#454545" stroke-opacity="1" stroke-width="1" fill="#00ff00" fill-opacity="1" points="11.35 -859.014 75 -822.719 138.65 -859.014 75 -895.31" />
<text x="51.175" y="-852.249" font-family="Arial" font-size="16" fill="#121212">Node1</text>
<ellipse fill="#00ff00" fill-opacity="1" stroke="#454545" stroke-opacity="1" stroke width="1" cx="0" cy="-571.945" rx="69.945" ry="69.945" />
<text x="-61.945" y="-565.179" font-family="Arial" font-size="16" fill="#121212">Node2</text>
</g>
</svg>
在基本层面上,我想要完成的是获得所有“文本”元素,而不是形状。简单的事情:
List<XElement> textList = xml.Descendants("text").ToList();
但是,这不起作用。我发现XML可能没有正确序列化,但我不认为是这种情况。 XML当前是使用字符串中的XElement.Parse()创建的。具体来说,字符串实际上是一个SVG文件,但我不知道这会如何影响它作为XML的能力。如果这就是它无法正常工作的原因,那么知道这一点会很棒。