Here is a sample XML file:
<Project attri1="build">
<Import Project="blahblah" xmlns="someURI" />
<Property>
...
</Property>
<Property>
...
</Property>
...
<ItemGroup>
<Folder Include="Scripts" />
<Folder Include="Scripts/1.0" />
<Folder Include="Scripts/2.0/" />
...
</ItemGroup>
... some irrelevant ItemGroup is here
<ItemGroup>
<None Include="Scripts/1.0/001.sql" />
<None Include="Scripts/2.0/002.sql" />
</ItemGroup>
...
</Project>
The above XML file is based on the template of Visual Studio's sqlproj file. It is distinguished based on what kind of nodes are inside.
My research:
import xml.dom.minidom
sql = xml.dom.minidom.parse('file.sqlproj')
itemGroup = sql.getElementsByTagName('ItemGroup')
folderGroup = itemGroup[0] # The first ItemGroup has folders
sqlGroup = itemGroup[2] # The 3rd ItemGroup has sql file list.
I want to add <Folder Include="newpath" /> and <Folder Include="newsql" /> into appropriate ItemGroup using Python's xml.dom.minidom library, and eventually override the original sqlproj file.
How to do that?
If you suggest other built-in libraries, please give an example, thanks.