Parsing : String to XML

守給你的承諾、 提交于 2019-12-06 14:38:25

The BookingDetails tag is self-closed on this line:

<BookingDetails  Amount="768"  Comment="Hotel Travel Purchase"  CurrencyCode="INR"  PurchaseType="Hotel"  SupplierName="SomeHotel"  CardAlias="C_ALIAS"  ValidFor="-1D"  CurrencyType="B" />

But when there is a separate closing BookingDetails element:

</BookingDetails>

Also, the <MasterDetails /> is not properly closed on the last line. Should be </MasterDetails> instead of <MasterDetails />.


Note that you can parse this XML in the "recover" mode if lxml.etree is used:

import lxml.etree as ET

parser = ET.XMLParser(recover=True)
tree = ET.ElementTree(ET.fromstring(data, parser=parser)) 

Or, use BeautifulSoup with xml features:

from bs4 import BeautifulSoup

soup = BeautifulSoup(data, "xml")
print(soup.prettify())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!