I have a file which uses a xml schema. That looks like this:
<maplayer simplifyAlgorithm="0" minimumScale="0" maximumScale="2500" simplifyDrawingHints="0" readOnly="0" minLabelScale="0" maxLabelScale="1e+08" simplifyDrawingTol="1" geometry="Point" simplifyMaxScale="1" type="vector" hasScaleBasedVisibilityFlag="1" simplifyLocal="1" scaleBasedLabelVisibilityFlag="0">
<id></id>
<datasource>port=1521 user=test_user password=test_passwd</datasource>
<keywordList>
<value></value>
</keywordList>
<featformsuppress>0</featformsuppress>
<editorlayout>generatedlayout</editorlayout>
<widgets/>
<conditionalstyles>
<rowstyles/>
<fieldstyles/>
</conditionalstyles>
</maplayer>
</projectlayers>
<properties>
<Variables>
<variableNames type="QStringList">
<value>paswd</value>
<value>user</value>
</variableNames>
<variableValues type="QStringList">
<value>5zdgf</value>
<value>dgdgdgfdg</value>
</variableValues>
</Variables>
<customproperties>
<property key="labeling/textColorR" value="0"/>
<property key="labeling/textTransp" value="0"/>
<property key="labeling/upsidedownLabels" value="0"/>
<property key="labeling/useSubstitutions" value="false"/>
<property key="labeling/wrapChar" value=""/>
<property key="labeling/xOffset" value="0"/>
<property key="labeling/yOffset" value="0"/>
<property key="labeling/zIndex" value="0"/>
<property key="variableNames"/>
<property key="variableValues"/>
</customproperties>
So I wanted to use python to delte the password and user part as well as the variables parts. I use the following code:
import re
with open('C:\myfile.txt') as oldfile, open('C:\myfile_withoutPW.txt', 'w') as newfile:
oldText = oldfile.read()
noPass = re.sub(r'(password=).*?(?=\s) ', '', oldText.rstrip())
noPass_noUser = re.sub(r'(user=).*?(?=\s) ', '', noPass.rstrip())
# fehlt noch
newText = re.sub(re.escape(r'<property key="variableNames"/>'), '', noPass_noUser.rstrip())
newText = re.sub(re.escape(r'<property key="variableValues"/>'), '', newText.rstrip())
newfile.write(newText)
This works, but not completly as I wanted it to, it deltes the parts but it leaves empty lines, like:
<property key="labeling/wrapChar" value=""/>
<property key="labeling/xOffset" value="0"/>
<property key="labeling/yOffset" value="0"/>
<property key="labeling/zIndex" value="0"/>
</customproperties>
<blendMode>0</blendMode>
<featureBlendMo
How can i solve this to completly delte those lines/parts form my txt file?