1from bs4 import BeautifulSoup
2
3soup = BeautifulSoup(open('W2Testfile.xml', encoding='utf-8'), 'lxml')
4
5# Just copy from and doc and lower search or write lower case
6sub_id = soup.find('SubmissionId'.lower())
7# Tag and text
8print(sub_id)
9print(sub_id.text)
10
11#---| Take out part eg doc 2,then <find_all> of a tag that there are several of
12doc_2 = soup.find('returndata', {'documentcnt': '2'})
13dep_detail = doc_2.find_all('DependentDetail'.lower())
14print('-' * 30)
15print(dep_detail[0].find('dependentrelationshipcd'))
16print(dep_detail[0].find('dependentrelationshipcd').text)
17
1import xmltodict as xtd
2import os
3
4xml_file_content = ""
5
6catalog_dir = os.chdir('directory')
7catalog_dir_array = os.listdir(catalog_dir)
8
9if("nameOfFile.xml" in catalog_dir_array):
10 catalog_file_content = open("nameOfFile.xml", "r").read()
11
12catalog_file_content_dict = xtd.parse(catalog_file_content)