From 4d108fca731bbd152ad058d007e2de6440f2c98a Mon Sep 17 00:00:00 2001 From: gilad_ilsar Date: Wed, 21 Sep 2016 22:49:44 +0300 Subject: change the xml cleaner to set tags as ###.* --- .gitignore | 15 --------------- .idea/lib2wiki.iml | 11 ----------- .idea/misc.xml | 12 +++++++++++- .idea/modules.xml | 2 +- .idea/parser.iml | 12 ++++++++++++ parsers/INL_xml_parser.py | 41 ++++++++++++++++++++--------------------- 6 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 .idea/lib2wiki.iml create mode 100644 .idea/parser.iml diff --git a/.gitignore b/.gitignore index 5e64fdb..7e99e36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1 @@ -# User-specific stuff: -.idea/workspace.xml -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - *.pyc \ No newline at end of file diff --git a/.idea/lib2wiki.iml b/.idea/lib2wiki.iml deleted file mode 100644 index 6711606..0000000 --- a/.idea/lib2wiki.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index de9bbc8..8e8cee7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,14 @@ - + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 9a7bd2d..405d108 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/parser.iml b/.idea/parser.iml new file mode 100644 index 0000000..6f63a63 --- /dev/null +++ b/.idea/parser.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/parsers/INL_xml_parser.py b/parsers/INL_xml_parser.py index 2ea9a9b..671d2d9 100644 --- a/parsers/INL_xml_parser.py +++ b/parsers/INL_xml_parser.py @@ -6,29 +6,28 @@ class INLXmlParser: self.whitelist = lst self.xmlpath = path - def clearxml(self): - xmltree = ET.parse(self.xmlpath) - # root == list of records - root = xmltree.getroot() - # create new data - newTreeRoot = ET.Element('data') + #expects to get a record as ElementTree + def clearxml(self, record): + # root == list of tags + root = record.getroot() # scan the datafields in the records and copy to the new one only the tags in the whitelist - for record in root: - # create new record - newRecord = ET.SubElement(newTreeRoot, 'record') - for field in record: - fieldtag = field.attrib.get('tag') - if fieldtag in self.whitelist: - newFieldTag = fieldtag - # tag 700 and 400 are the same - if newFieldTag == '700': - newFieldTag = '400' + # create new record + newRecord = ET.Element('record') + for field in root: + fieldtag = field.attrib.get('tag') + if fieldtag in self.whitelist: + tempTag = fieldtag + # tag 700 and 400 are the same + if tempTag == '700': + tempTag = '400' + for data in field: + newFieldTag = tempTag + newFieldTag +='.' + newFieldTag += data.attrib.get('code') newTag = ET.SubElement(newRecord, 'datafield', {'tag': newFieldTag}) - for data in field: - subData = ET.SubElement(newTag, data.tag, data.attrib) - subData.text = data.text + newTag.text = data.text - newTree = ET.ElementTree(newTreeRoot) - return newTree + newRecordTree = ET.ElementTree(newRecord) + return newRecordTree -- cgit v1.2.3