Sample Header Ad - 728x90

Identify empty VALUE in XML files and return exit command?

1 vote
0 answers
260 views
For instance, I have an XML file with the below content and the "NAME" Author and Assignee(s) have empty "VALUE". The main aim is to implement a check that can be applied to find XML files that have empty VALUE's. So is there a way I can create a script which can be used as a git hook(pre-commit) so that input to the script are the files that are being called by git commit (all files in that repo) or git commit (filename). And then the script should not allow to commit if the XML file has empty VALUEs. Type MANUAL Severity Normal Author Assignee(s) Is there a better approach than the one shown below? TIA def xmlvalidator(): dirlist = [] dirlist.append(os.getcwd().replace("\\","/")) filelists = filelist(dirlist) Flagvallists = [] for filename in filelists: xtree = et.parse(filename) root = xtree.getroot() xroot = root flag = 0 flagval = [] for i in range(len(xroot)): #xroot here should ATTRIBUTES (ATTRIBUTE IN ATTRIBUTES) s_name = xroot[i].text s_value = xroot[i].text if s_value == None: flagval.append(s_name) flag = 1 if flag==1: flagval.append(filename) Flagvallists.append(flagval) #sys.exit(1) #return True return Flagvallists EDIT: Thanks to @Paul_Pedant Seems like a simple and great solution, but how can the input be the same as the one called by git commit? and not the filename(A.xml) if grep "]*/>" A.xml; then echo errors found else echo not found fi
Asked by Vdgoa (11 rep)
Sep 11, 2020, 08:46 AM
Last activity: Sep 11, 2020, 11:03 AM