-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_rules.py
More file actions
45 lines (43 loc) · 1.78 KB
/
Copy pathparse_rules.py
File metadata and controls
45 lines (43 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
from xml.dom.minidom import parse
import xml.dom.minidom
# 使用minidom解析器打开 XML 文档
DOMTree = xml.dom.minidom.parse(path)
rules = DOMTree.documentElement
if rules.hasAttribute("shelf"):
print ("Root element : %s" % rules.getAttribute("shelf"))
# 在集合中获取所有rules
rulesss = rules.getElementsByTagName("rule")
fo = open("C:\\Users\\00123726\\PycharmProjects\\pyang\\pyang\\rules.txt", "w")
# 打印每个rule的详细信息
for rule in rulesss:
fo.write ("***************Rule_start***************\n")
rule_id = rule.getElementsByTagName('rule-id')[0]
fo.write ("Rule-id: %s" % rule_id.childNodes[0].data)
fo.write("\n")
typesss = rule.getElementsByTagName('type')
for type in typesss:
fo.write ("Type: %s" % type.childNodes[0].data)
fo.write("\n")
condition = rule.getElementsByTagName('condition')[0]
fo.write ("Condition: %s" % condition.childNodes[0].data)
fo.write("\n")
compatiable = rule.getElementsByTagName('compatiable')[0]
fo.write ("Compatiable: %s" % compatiable.childNodes[0].data)
fo.write("\n")
description = rule.getElementsByTagName('description')[0]
fo.write ("Description: %s" % description.childNodes[0].data)
fo.write("\n")
if (rule.getElementsByTagName('except-condition')):
except_condition = rule.getElementsByTagName('except-condition')[0]
fo.write("Except-condition: %s" % except_condition.childNodes[0].data)
fo.write("\n")
statementssss = rule.getElementsByTagName("statement")
stmt_tag = 0
for statement in statementssss:
fo.write("Statement" + str(stmt_tag) + ": %s" % statement.childNodes[0].data)
fo.write("\n")
stmt_tag= stmt_tag+1
fo.write("***************Rule_end***************")
fo.write("\n")