Python
- 1 ответ
- 0 вопросов
1
Вклад в тег
import xml.etree.ElementTree as ET
data = """
<ns2:Request xmlns:ns2="urn://www.example.com">
<ns2:User>
<ns2:Name>John</ns2:Name>
<ns2:Surname>Snow</ns2:Surname>
<ns2:Email>joihn.show@gmail.com</ns2:Email>
<ns2:Birthday>2005-10-23T04:00:00+03:00</ns2:Birthday>
</ns2:User>
</ns2:Request>
"""
namespaces = {"ns2": "urn://www.example.com"}
xml = ET.fromstring(data)
name = xml.find(".//ns2:Name", namespaces).text
surname = xml.find(".//ns2:Surname", namespaces).text
email = xml.find(".//ns2:Email", namespaces).text
birthday = xml.find(".//ns2:Birthday", namespaces).text
print("Name:", name)
print("Surname:", surname)
print("Email:", email)
print("Birthday:", birthday)