PYTHONPORTAL Telegram 4390
XML parsing

Вот три инструмента, которые помогут удобно разбирать и обрабатывать XML-документы:

> untangle — превращает XML в Python-объект

Простой способ получить доступ к тегам и атрибутам через точки.

import untangle
obj = untangle.parse('file.xml')
print(obj.root.child['name'])


> xmltodict — делает XML похожим на JSON

Преобразует XML в обычный словарь Python. Поддерживает атрибуты (@), текст (#text), namespaces, обратное преобразование (unparse) и стриминг для больших файлов.

import xmltodict
with open('file.xml') as f:
doc = xmltodict.parse(f.read())
print(doc['mydocument']['@has'])


> xmlschema — для работы с XSD-схемами

Позволяет валидировать XML по схеме, учитывает типы данных, удобно кодирует и декодирует.

from xmlschema import XMLSchema
schema = XMLSchema("schema.xsd")
data = schema.decode("file.xml")


Полезно для конфигов, API, валидации и парсинга сложных XML-документов ❤️

👉 @PythonPortal
Please open Telegram to view this post
VIEW IN TELEGRAM
👍297🔥2



tgoop.com/PythonPortal/4390
Create:
Last Update:

XML parsing

Вот три инструмента, которые помогут удобно разбирать и обрабатывать XML-документы:

> untangle — превращает XML в Python-объект

Простой способ получить доступ к тегам и атрибутам через точки.

import untangle
obj = untangle.parse('file.xml')
print(obj.root.child['name'])


> xmltodict — делает XML похожим на JSON

Преобразует XML в обычный словарь Python. Поддерживает атрибуты (@), текст (#text), namespaces, обратное преобразование (unparse) и стриминг для больших файлов.

import xmltodict
with open('file.xml') as f:
doc = xmltodict.parse(f.read())
print(doc['mydocument']['@has'])


> xmlschema — для работы с XSD-схемами

Позволяет валидировать XML по схеме, учитывает типы данных, удобно кодирует и декодирует.

from xmlschema import XMLSchema
schema = XMLSchema("schema.xsd")
data = schema.decode("file.xml")


Полезно для конфигов, API, валидации и парсинга сложных XML-документов ❤️

👉 @PythonPortal

BY Python Portal




Share with your friend now:
tgoop.com/PythonPortal/4390

View MORE
Open in Telegram


Telegram News

Date: |

So far, more than a dozen different members have contributed to the group, posting voice notes of themselves screaming, yelling, groaning, and wailing in various pitches and rhythms. Deputy District Judge Peter Hui sentenced computer technician Ng Man-ho on Thursday, a month after the 27-year-old, who ran a Telegram group called SUCK Channel, was found guilty of seven charges of conspiring to incite others to commit illegal acts during the 2019 extradition bill protests and subsequent months. SUCK Channel Telegram To edit your name or bio, click the Menu icon and select “Manage Channel.” In 2018, Telegram’s audience reached 200 million people, with 500,000 new users joining the messenger every day. It was launched for iOS on 14 August 2013 and Android on 20 October 2013.
from us


Telegram Python Portal
FROM American