使用python解析VisualStudio .csproj文件的最佳方法 [英] Best way to parse VisualStudio .csproj file using python

查看:184
本文介绍了使用python解析VisualStudio .csproj文件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用python解析Visual Studio .csproj文件进行进一步修改的最佳方法是什么?

What is the best way to parse Visual Studio .csproj file using python, for further modification?

它是一些.csproj文件:

...
<ItemGroup>
    <Reference Include="SomeAssembly, Version=1.1.1.1"/>      
...
</ItemGroup>
...

我要插入这个:

<HintPath>path/to/SomeAassembly.dll</HintPath>

进入<Reference/>节点.

推荐答案

VS项目文件是XML. Python随附了许多XML解析库: http://docs.python.org/library/markup .html

VS project files are XML. Python comes with a number of XML parsing libraries: http://docs.python.org/library/markup.html

xml.parsers.expatxml.minidom中的任何一个都可以完成您描述的内容.对于处理像VS项目文件这样的小型XML文档,在它们之间进行选择是一个问题.文档中每个示例的示例代码都可以帮助您做出决定.

Either of xml.parsers.expat or xml.minidom could accomplish what you describe. For processing small XML documents like VS project files, choosing among them is a matter of taste. The example code in the documentation for each should help you decide.

最好的替代方法是,在xml.sax API中使用过滤器对象.

这篇关于使用python解析VisualStudio .csproj文件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆