exception':“无法解析 QName 'SOAP:',第 1 行,第 7 列

问题描述 投票:0回答:0

我从 api 得到了这个 xml,但之后我想使用 xpath 获取 xml 属性的值,但在第一步中

tree = etree.parse(StringIO(hotel_details_logs))

我遇到异常/错误。

"<?xml version=\\'1.0\\' encoding=\\'utf8\\'?>\n<ns0: Envelope xmlns: ns0=\"http: //schemas.xmlsoap.org/soap/envelope/\" xmlns: ns1=\"http: //docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns: ns2=\"http: //www.travelport.com/schema/hotel_v46_0\" xmlns: ns3=\"http: //www.travelport.com/schema/common_v46_0\"><ns0: Header><ns1: Security><ns1: UsernameToken><ns1: Username>Universal API/uAPI4685534400-909bfc29</ns1: Username><ns1: Password Type=\"http: //docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">F&amp;c6gZ7%4*</ns1: Password></ns1: UsernameToken></ns1: Security></ns0: Header><ns0: Body><ns2: HotelDetailsReq TargetBranch=\"P3398890\" RetrieveProviderReservationDetails=\"false\" ReturnMediaLinks=\"false\" ReturnGuestReviews=\"false\"><ns3: BillingPointOfSaleInfo OriginApplication=\"UAPI\" /><ns2: HotelProperty HotelChain=\"YX\" HotelCode=\"5091202\" Name=\"JUSTA OFF MG ROAD\" /><ns2: HotelDetailsModifiers NumberOfAdults=\"1\" RateRuleDetail=\"Complete\" NumberOfRooms=\"1\" ProcessAllNegoRatesInd=\"false\"><ns3: PermittedProviders><ns3: Provider Code=\"1G\" /></ns3: PermittedProviders><ns2: HotelStay><ns2: CheckinDate>2023-03-23</ns2: CheckinDate><ns2: CheckoutDate>2023-03-24</ns2: CheckoutDate></ns2: HotelStay></ns2: HotelDetailsModifiers></ns2: HotelDetailsReq></ns0: Body></ns0: Envelope>"

命名空间=

{'x': 'http://schemas.xmlsoap.org/soap/envelope/',
                  'y': 'http://www.travelport.com/schema/universal_v46_0',
                  'z': 'http://www.travelport.com/schema/hotel_v46_0',
                  'p': 'http://www.travelport.com/schema/common_v46_0'}

我尝试验证 xml,但没有给出任何有价值的结果。如何使用 xpath 获取值?

hotel_property = root.xpath(
    '/x:Envelope/x:Body/z:HotelDetailsRsp/z:RequestedHotelDetails/z:HotelProperty', namespaces=namespaces)
xml xml-parsing elementtree
© www.soinside.com 2019 - 2024. All rights reserved.