現在、いくつかの既存の XML を手動で作成したいくつかのクラスに非整列化しようとしています。問題は、JaxB は天気要素を期待しているが、天気要素を見つけたというエラーが常に表示されることです。(?)
javax.xml.bind.UnmarshalException: 予期しない要素 (uri:"http://www.aws.com/aws"、local:"weather")。期待される要素は <{}api>、<{}location>、<{}weather> です
要素の名前に「aws:」を付けたり付けたりせずに試しました。
これが私の天気クラスです:
@XmlRootElement(name = "aws:weather")
public class WeatherBugWeather
{
private WeatherBugApi api;
private List<WeatherBugLocation> locations;
private String uri;
@XmlElement(name="aws:api")
public WeatherBugApi getApi()
{
return this.api;
}
@XmlElementWrapper(name = "aws:locations")
@XmlElement(name = "aws:location")
public List<WeatherBugLocation> getLocations()
{
return this.locations;
}
public void setApi(WeatherBugApi api)
{
this.api = api;
}
public void setLocations(List<WeatherBugLocation> locations)
{
this.locations = locations;
}
@XmlAttribute(name="xmlns:aws")
public String getUri()
{
return this.uri;
}
public void setUri(String uri)
{
this.uri = uri;
}
}
そして、それが私が解析しようとしている XML です。
<?xml version="1.0" encoding="utf-8"?>
<aws:weather xmlns:aws="http://www.aws.com/aws">
<aws:api version="2.0" />
<aws:locations>
<aws:location cityname="Jena" statename="" countryname="Germany" zipcode="" citycode="59047" citytype="1" />
</aws:locations>
</aws:weather>
何が間違っているのかよくわかりません。ヒントはありますか?問題は xmlns の定義にあると思われますが、どうすればよいかわかりません。(uri-property を見ればわかります。これは失敗したアイデアの 1 つです。^^) はい、名前空間を設定しようとしましたが、名前ではなく名前空間の uri を設定しています。