I am trying to iterate over a bunch of .xml files in a directory.
For this purpose, I wrote a python script:
#!/usr/bin/python3.5
import os
import glob
pathToDirectory = '/home/anton/Documents/Repo_from_GitHub/ResiShared/templates/'
for filename in os.listdir(pathToDirectory):
file = open(pathToDirectory.__add__(filename), "r")
count = 0
for line in file:
if line.__contains__('xmlns="http://xml.juniper.net/xnm/1.1/xnm"') \
| line.__contains__('xmlns="http://tail-f.com/ned/cisco-ios-xr"') \
| line.__contains__('xmlns="http://tail-f.com/ned/arista-dcs"'):
++count
elif line.__contains__('tags="replace"'):
--count
elif (line.__contains__('</config>') \
| line.__contains__('</config-template>')) & count > 0:
print ('There are ' + str(count) + ' tags="replace" missing in the ' + file.name)
It is working without any bug spotted, but also I got no output from the last "elif", but it definitely should be.
Here is an example of .xml file: xml file example
UPDATE: I do not need any kind of XML parser here, core Python functionality should be enough.