JAXB를 사용하여 이름, 스테이션 ID, 위도/경도 및 URL과 같은 기상 관측소 정보가 포함 된 XML 파일을 구문 분석 할 프로젝트를 진행 중입니다. 지금 나는 기상 관측소를 이름으로 만 인쇄하여 모든 것을 시험 할 생각입니다. 내 코드를 디버깅했지만 실행하려고하면 다음 오류가 발생합니다.JAXB XML 구문 분석 문제
스레드 "main"의 예외 javax.xml.bind.UnmarshalException : 예기치 않은 요소 (uri : "", 로컬 : "wx_station_index") . 예상되는 요소는 (없음)
설명이 있습니까? 어떤 도움을 주시면 감사하겠습니다. 내 코드와 XML의 샘플은 아래에 게시되어 있습니다 :
//create criteria for weather station info
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class StationTest {
/**
* @param args
*/
@XmlElement(name = "station_id")
String station_id;
@XmlElement(name = "state")
String state;
@XmlElement(name = "station_name")
String stationName;
@XmlElement(name = "latitude")
double latitude;
@XmlElement(name = "longitude")
double longitude;
@XmlElement(name = "html_url")
String htmlUrl;
public String getStationID(){
return station_id;
}
public void setStationId(String station_id)
{
this.station_id = station_id;
}
public String getState(){
return state;
}
public void setState(String state)
{
this.state = state;
}
public String getStationName(){
return stationName;
}
public void setStationName(String station_name)
{
this.stationName = stationName;
}
public double getLatitude(){
return latitude;
}
public void setLatitude(double latitude)
{
this.latitude = latitude;
}
public double getLongitude(){
return longitude;
}
public void setLongitude(double longitude)
{
this.longitude = longitude;
}
public String getUrl(){
return htmlUrl;
}
public void setUrl(String url){
this.htmlUrl = htmlUrl;
}
} 수입 인 java.util.ArrayList; 그 wx_station_index 오타없는 가정
<?xml version="1.0" encoding="UTF-8"?>
<wx_station_index>
<credit>NOAA's National Weather Service</credit>
<credit_URL>http://weather.gov/</credit_URL>
<image>
<url>http://weather.gov/images/xml_logo.gif</url>
<title>NOAA's National Weather Service</title>
<link>http://weather.gov</link>
</image>
<suggested_pickup>08:00 EST</suggested_pickup>
<suggested_pickup_period>1140</suggested_pickup_period>
<station>
<station_id>NFNA</station_id>
<state>FJ</state>
<station_name>Nausori</station_name>
<latitude>-18.05</latitude>
<longitude>178.567</longitude>
<html_url>http://weather.noaa.gov/weather/current/NFNA.html</html_url>
<rss_url>http://weather.gov/xml/current_obs/NFNA.rss</rss_url>
<xml_url>http://weather.gov/xml/current_obs/NFNA.xml</xml_url>
</station>
<station>
<station_id>KCEW</station_id>
<state>FL</state>
<station_name>Crestview, Sikes Airport</station_name>
<latitude>30.79</latitude>
<longitude>-86.52</longitude>
<html_url>http://weather.noaa.gov/weather/current/KCEW.html</html_url>
<rss_url>http://weather.gov/xml/current_obs/KCEW.rss</rss_url>
<xml_url>http://weather.gov/xml/current_obs/KCEW.xml</xml_url>
</station>
당신은 실제 XML을 제공 할 수 있습니다하시기 바랍니다. – 3xil3
그냥 내 XML을 추가했습니다. – David
복사본 붙여 넣기 오류이거나 의도적으로 의도 한 것이 확실하지 않지만가 닫히지 않았습니다. 이것이 의도적으로라면, 이것은 우리가 스테이션 요소를 찾을 것으로 예상되는 wx_station_index 요소를 기대한다는 것을 의미합니다. 귀하의 자바 코드에서, 우리는 역의 목록을 처리하고 있습니다 (역 요소가 있다면 거기에 맞을 것입니다) –
3xil3