0
다음 xml 값을 파싱하지 못하는 것 같습니다. 내가 google-http-java 클라이언트를 사용했다면 xml 형식의 구문 분석을위한 파서 클래스는 무엇이겠습니까? 샘플 xml 및 파서 아래google-http-client-xml을 사용하여 xml 파싱 : XmlObjectParser를 사용하여 XML 요소 콘텐츠 및 속성 구문 분석
<feed>
<text start="1" end="10"> Text 1 </text>
<text start="2" end="20"> Text 2 </text>
<text start="3" end="30"> Text 3 </text>
<text start="4" end="40"> Text 4 </text>
<text start="5" end="50"> Text 5 </text>
</feed>
Class Feed {
@Key("text")
public List<Text> textList;
}
Class Text {
@Key("@start")
public String startTime;
@Key("@end")
public String endTime;
}
분명히하려면 시작 속성 값, 종료 속성 값 및 텍스트 내용을 원합니다. 작동하는 것으로 보이는 것은 다음과 같습니다.
HttpRequestFactory httpRequestFactory =
HTTP_TRANSPORT.createRequestFactory(
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
request.setParser(new XmlObjectParser(new XmlNamespaceDictionary().set("", "")));
}
});
Feed feedObject = httpResponse.parseAs(Feed.class);
하지만 콘텐츠 값을 가져올 수 없습니다.
나는 다음과 같은
Class Feed {
@Key("text")
public List<String> textList;
}
에 공급 클래스를 변경하면 나는 내용 만이 아닌 속성 값을 얻을 수 있습니다!
모든 샘플 소스 코드는