-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmltester.py
More file actions
executable file
·53 lines (39 loc) · 1.68 KB
/
xmltester.py
File metadata and controls
executable file
·53 lines (39 loc) · 1.68 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
46
47
48
49
50
51
52
53
__author__ = 'Clive'
import os
from os import walk
import sqlite3
import xmlhelper
import dbhelper
dbname = "uscdb.db"
xmlpath = r"./xmltest/"
# these are from ustitle.css
aboveSectionLevels = ["title", "subtitle", "chapter", "subchapter", "part", "subpart", "division", "subdivision", "level",
"appendix", "compiledAct", "courtRules", "courtRule", "reorgnizationPlans", "reorganizationPlan"]
belowSectionLevels = ["subsection", "paragraph", "subparagraph", "clause", "subclause", "item"
"subitem", "subsubitem", "level"]
titleNameTable = "titleNames"
titleNameTableFormat = "(_id INTEGER PRIMARY KEY AUTOINCREMENT, titleNumText TEXT, titleName TEXT)"
titleNameTableKeyCol = "titleNumText"
titleChTableSuffix = "ch"
titleSecTableSuffix = "sec"
eachTitleChFormat = "(_id INTEGER PRIMARY KEY AUTOINCREMENT, ChNo TEXT, ChHeading TEXT, SecStart TEXT, SecEnd TEXT)"
eachTitleSecFormat = "(_id INTEGER PRIMARY KEY AUTOINCREMENT, SecNo TEXT, SecHeading TEXT, SecContent TEXT)"
# hange the current diretory to the xml directory
os.chdir(xmlpath)
# find the path of where the xml files are stored
mypath = os.path.dirname(__file__) + xmlpath
# get all the xml files in the directory
xmlFiles = []
for (dirpath, dirnames, filenames) in walk(mypath):
for f in filenames:
froot, fext = os.path.splitext(f)
if fext == ".xml" or fext == ".xml-bak":
xmlFiles.append(f)
for f in xmlFiles:
print ("Testing " + f + "...")
root = xmlhelper.extract_xml(f, mypath)
mainroot = root.find('./main/title')
if mainroot is None:
mainroot = root.find('./appendix')
for et in mainroot.iterfind('.//section/content/*'):
print (et.tag)