我有一个 Web 服务方法,它解析 SVG 字符串以删除某些元素,然后将其返回。
这是 SVG 字符串的一部分:
<g id="wrapper">
<g id="inner">
<title>Layer 1</title>
...etc
这是代码:
XDocument x2 = XDocument.Parse(svgString);
var inner = (from el in x2.Root.Elements("g")
where (string)el.Attribute("id") == "inner"
select el);
inner.Remove();
return x2.ToString();
首先,为什么是Count
0 inner
?
其次,这是“删除”元素的正确方法还是我需要XDocument
在返回之前以某种方式保存它?
编辑:这是完整的 SVG 字符串:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"[]>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px" width="374.173px" height="524.409px" viewbox="0 0 374.173 524.409"
enable-background="new 0 0 374.173 524.409" xml:space="preserve">
<g id="wrapper">
<g id="inner">
<title>Layer 1</title>
<defs>
<rect id="SVGID_1_" x="16.086" y="98.896" width="344.903" height="413.334" />
</defs>
<clipPath id="SVGID_2_">
<use xlink:href="#SVGID_1_" overflow="visible" />
</clipPath>
<g clip-path="url(#SVGID_2_)">
<defs>
<rect id="SVGID_3_" x="-8.96" y="53.896" width="382.524" height="473.956" />
</defs>
<clipPath id="SVGID_4_">
<use xlink:href="#SVGID_3_" overflow="visible" />
</clipPath>
<g transform="matrix(1 0 0 1 3.341429e-007 -1.529841e-006)" clip-path="url(#SVGID_4_)">
<image overflow="visible" width="367" height="445" id="img11" xlink:href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEARQBFAAD/7AARRHVja3kAAQAEAAAAHgAA/+4AIUFkb2JlAGTAAAAAAQMA EAMCAwYAAAlpAAAVEAAANsH/2wCEABALCwsMCxAMDBAXDw0PFxsUEBAUGx8XFxcXFx8eFxoaGhoX Hh4jJSclIx4vLzMzLy9AQEBAQEBAQEBAQEBAQEABEQ8PERMRFRISF...........">
</image>
</g>
</g>
</g>
</g>
<g>
<title>Layer 2</title>
<text transform="matrix(1 0 0 1 61.3745 48.5068)"><tspan x="0" y="0" fill="#9FA1A4" font-family="'Noteworthy-Bold'" font-size="24">testing 123</tspan></text>
</g>
</svg>