C# 如何从svg扩展svg读取xml代码
所以我在阅读一些xml时遇到了问题。 我需要阅读C# 如何从svg扩展svg读取xml代码,c#,asp.net,xml,C#,Asp.net,Xml,所以我在阅读一些xml时遇到了问题。 我需要阅读属性 SVG如下所示: <?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="700pt" height="820pt" viewBox="6
属性
SVG如下所示:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="700pt" height="820pt" viewBox="60 25 500 600"
version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<g id="id1">
<g id="id3">
<g id="id3">
<path clip-path="url(#SVG_CP_1)" fill="#000000" city="Amsterdam" />
</g>
</g>
</g>
</svg>
我的代码:
XDocument xdoc = XDocument.Load("D:/Users/me/Desktop/Website/files/test.svg");
xdoc.Descendants("path").Select(p => new
{
city= p.Attribute("city").Value,
}).ToList().ForEach(p =>
{
html.Append("City: " + p.city+ "<br>");
});
XDocument xdoc=XDocument.Load(“D:/Users/me/Desktop/Website/files/test.svg”);
子体(“路径”)。选择(p=>new
{
城市=p.属性(“城市”).值,
}).ToList().ForEach(p=>
{
html.追加(“城市:+p.City+”
”;
});
现在,当我从svg文件中排除
时,这段代码非常有效。但我需要把它放在我的档案里 根元素svg
包含URI为http://www.w3.org/2000/svg
。请注意,所有不带前缀的子元素都隐式继承祖先的默认名称空间
现在要引用名称空间中的元素,可以使用XNamespace
和目标元素的本地名称的组合:
XDocument xdoc = ...;
XNamespace ns = "http://www.w3.org/2000/svg";
xdoc.Descendants(ns+"path").Select(p => new
{
....
})
....