mirror of
https://codeberg.org/mclemens/esm2markdown.git
synced 2024-09-26 14:16:01 -04:00
added function to validate XML file
This commit is contained in:
parent
853a3eacdf
commit
5776df5982
@ -83,6 +83,29 @@ def addLine(typ,level,key,value):
|
|||||||
output = re.sub('\$\$',"!",output)
|
output = re.sub('\$\$',"!",output)
|
||||||
mklines.append(output)
|
mklines.append(output)
|
||||||
|
|
||||||
|
def validateXML(xmlfile):
|
||||||
|
|
||||||
|
xmlok = True
|
||||||
|
parser = etree.XMLParser(strip_cdata=False)
|
||||||
|
with open(xmlfile, "rb") as source:
|
||||||
|
root = etree.parse(source, parser=parser)
|
||||||
|
|
||||||
|
temp = root.find("rules")
|
||||||
|
|
||||||
|
msglist = []
|
||||||
|
|
||||||
|
for e in temp:
|
||||||
|
msg = e.findtext("message")
|
||||||
|
if msg in msglist:
|
||||||
|
print("Duplicate rule: " + msg)
|
||||||
|
xmlok = False
|
||||||
|
msglist.append(msg)
|
||||||
|
|
||||||
|
if xmlok == False:
|
||||||
|
print("The XML file contains some errors. Please fix the input file and rerun this script.")
|
||||||
|
|
||||||
|
return xmlok
|
||||||
|
|
||||||
|
|
||||||
# Sorts input XML alphabetically based on Rule Names
|
# Sorts input XML alphabetically based on Rule Names
|
||||||
def sortXML(xmlfile):
|
def sortXML(xmlfile):
|
||||||
@ -355,5 +378,6 @@ if __name__=="__main__":
|
|||||||
print('Example: python esm2markdown RuleExport.xml documentation.mk')
|
print('Example: python esm2markdown RuleExport.xml documentation.mk')
|
||||||
else:
|
else:
|
||||||
readConfig()
|
readConfig()
|
||||||
|
if validateXML(sys.argv[1]) == True:
|
||||||
parseXML(sys.argv[1])
|
parseXML(sys.argv[1])
|
||||||
writeMarkdownFile(sys.argv[2])
|
writeMarkdownFile(sys.argv[2])
|
||||||
|
Loading…
Reference in New Issue
Block a user