-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXMLParser.py
More file actions
26 lines (22 loc) · 795 Bytes
/
XMLParser.py
File metadata and controls
26 lines (22 loc) · 795 Bytes
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
from xml.dom import minidom
NAME=""
fhandoutput = open('ExtractedAddresses.txt', 'w')
ctr=0
xmldoc = minidom.parse('CNARIndexCleansed.xml')
itemlist = xmldoc.getElementsByTagName('field')
for s in itemlist:
if s.attributes['name'].value == 'complete_address':
ctr = ctr + 1
try:
NAME = s.getElementsByTagName("val")[0].childNodes[0].data
fhandoutput.write (str(ctr)+"|"+NAME+"\n")
except IndexError:
fhandoutput.write (str(ctr)+"|"+"No childNodes for this element"+"\n")
if s.attributes['name'].value == 'dpid':
try:
NAME = s.getElementsByTagName("val")[0].childNodes[0].data
fhandoutput.write (str(ctr)+"|"+NAME+"\n")
except IndexError:
fhandoutput.write (str(ctr)+"|"+"No childNodes for this element"+"\n")
print("Processing completed")
fhandoutput.close()