TRiBByX
8/25/2017 - 11:11 AM

Handle Json and XML

Handle Json and XML

import json
from lxml import etree
import xml.etree.ElementTree as ET
from bs4 import BeautifulSoup

'''
Get's the xml data from the data folder. 
Also this function sorts the data into 2 
smaller lists, which contains loads of
nested lists and dicts. If this is to be
used outside of the context of the 
formatter, then there should be some 
more sorting of the data.
'''
def xml_get():
	try:
		doc = ET.parse('data/data.xml')
		report = doc.findall('Report')
		reports = report[0]
		policies = doc.findall('Policy')
		tag_list = [reports, policies]
	except Exception as e:
		return e

	return tag_list

'''
Gets the json data from the data folder.
This doesnt sort any of the data, this 
is because it doesnt need to be sorted
as much.
'''
def json_get():
	try:
		with open('data/data.json') as json_data:
			data = json.load(json_data)
	except Exception as e:
		return e
	return data