xmltodict 모듈설치
pip install xmltodict
xml sample
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)
xml 데이터를 dictionary (json) 타입으로 변경
import json
import xmltodict
with open('sample.xml', encoding='utf-8') as f:
doc = xmltodict.parse(f.read())
json_data = json.loads(json.dumps(doc))
print(json_data)
----------------------------------------------------------------
{'catalog': {'book': [{'@id': 'bk101',
'author': 'Gambardella, Matthew',
'title': "XML Developer's Guide",
'genre': 'Computer',
'price': '44.95',
'publish_date': '2000-10-01',
'description': 'An in-depth look at creating applications \n with XML.'},
{'@id': 'bk102',
'author': 'Ralls, Kim',
'title': 'Midnight Rain',
'genre': 'Fantasy',
'price': '5.95',
'publish_date': '2000-12-16',
.............
.............
'Python > Python Programming' 카테고리의 다른 글
[ Python ] 웹 서버 날짜 확인 하기 (0) | 2023.05.14 |
---|---|
[ Python ] ntplib 모듈을 이용한 시간 동기화 점검 (0) | 2023.05.14 |
[ Python ] numpy를 이용한 1차원 배열 2 차원 배열로 변환 (0) | 2023.05.12 |
[ Python ] 날짜형식의 문자열 타입을 datetime 타입 형식으로 변환 (0) | 2023.05.03 |
[ Python ] difflib 모듈 ( 문자열 비교, 유사도 ) (0) | 2023.04.24 |
[ Python ] elastcisearch index 생성, 삭제, 조회 (0) | 2023.04.14 |
[ Python ] Remine API 사용하기 (0) | 2023.03.21 |
[ Python ] Tree Graph 만들기 (0) | 2023.02.15 |