2012-09-17 90 views
1

我需要能够编辑已在Adobe Illustrator中呈现的SVG文件的文本和图像。用C#操纵SVG文件

如何遍历SVG文件的元素,检查type = text,更改值并将文件保存到磁盘?有没有可以帮助我的图书馆?

到目前为止,我已经尝试过this basic library,但它对于复杂的SVG结构并不适用。

回答

1

这可能会很晚,但为了其他人的利益,如果他们登陆此页面,您可以使用HTMLAgilityPack。这里是链接到一个类似的问题:What is the best way to parse html in C#?

我已经在我的情况下用它地方,我需要编辑的SVG字符串替换一些值是这样的:

HtmlDocument theDocument = new HtmlDocument(); 
    theDocument.LoadHtml(svgChartImg1); 

    HtmlNodeCollection theNodes = theDocument.DocumentNode.SelectNodes("//tspan"); 

这里,svgChartImg1是SVG xml字符串。