gpt4 book ai didi

java - 解析 XM 返回 URI 不是绝对的

转载 作者:太空宇宙 更新时间:2023-11-04 14:58:12 26 4
gpt4 key购买 nike

我正在尝试解析以下 SOAP 响应,但代码返回以下异常

SEVERE:   java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1095)
at javax.xml.bind.JAXB.toSource(JAXB.java:306)
at javax.xml.bind.JAXB.unmarshal(JAXB.java:220)
......

回应

<?xml version="1.0" encoding="utf-8"?>
<SearchFlightsResponse xmlns="ElsyArres.API">
<SoapMessage>
<Username>Test</Username>
<Password>Test</Password>
<LanguageCode>EN</LanguageCode>
<ErrorMessage />
<ErrorCode>0</ErrorCode>
<AppVersion>8.0.3</AppVersion>
<Request>
<Departure>BER</Departure>
<Destination>LON</Destination>
<DepartureDate>2014-10-18</DepartureDate>
<ReturnDate />
<NumADT>1</NumADT>
<NumINF>0</NumINF>
<NumCHD>0</NumCHD>
<CurrencyCode>EUR</CurrencyCode>
<CarrierList />
<FareClasses />
<Providers />
<WaitForResult>true</WaitForResult>
<NearbyDepartures>false</NearbyDepartures>
<NearbyDestinations>false</NearbyDestinations>
<RROnly>false</RROnly>
<MetaSearch>false</MetaSearch>
</Request>
<Response>
<SearchFlightId>140408111958-02-11428-310</SearchFlightId>
<Roundtrip>false</Roundtrip>
<CurrencyCode>EUR</CurrencyCode>
<Flights>
<Flight>
<Outbound>
<CarName>Test Airline</CarName>
<CarCode>_2</CarCode>
<DepName>Berlin</DepName>
<DepCode>BER</DepCode>
<DestName>London</DestName>
<DestCode>LON</DestCode>
.....

代码

       SOAPMessage sm = response;
ByteArrayOutputStream out = new ByteArrayOutputStream();
sm.writeTo(out);


this.results = (SearchFlightsResponse) JAXB.unmarshal(sm.toString(), SearchFlightsResponse.class);
System.err.println(">" + results.getSoapMessage().getUsername());

响应类

@XmlRootElement(name="SearchFlightsResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class SearchFlightsResponse {
@XmlElement(name = "SoapMessage")
private SoapMessage soapMessage;
.....

@XmlRootElement(name="SoapMessage")
@XmlAccessorType(XmlAccessType.FIELD)
public class SoapMessage {
@XmlElement(name="Username")
private String username;
@XmlElement(name="Password")
private String password;
....

package-info.java

@XmlSchema( 
namespace = "ElsyArres.API",
elementFormDefault = XmlNsForm.QUALIFIED)
package com.myProject.wegolo;

import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

最佳答案

XML 命名空间 - xmlns 属性应遵循 URL 约定,例如“file:”、“classpath:”、“http://”、“ftp://”、“db:” .

就你而言,事实并非如此。

参见http://openrules.com/rulesrepository.htm

关于java - 解析 XM 返回 URI 不是绝对的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22935965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com