2013-12-13 4 views
0

저는 XStream 라이브러리를 사용하고 있습니다. XML 서비스의xml을 자바 객체로 변환하는 데 어려움이 있습니다.

링크 http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=ttc&r=54

내 수업 ......

package com.example.myjakcontest; 

import java.util.List; 

import com.thoughtworks.xstream.annotations.XStreamAlias; 

public class Body { 

    @XStreamAlias("copyright") 
    private String _copyright; 
    private Route route; 

    public String get_copyright() { 
     return this._copyright; 
    } 

    public void set_copyright(String _copyright) { 
     this._copyright = _copyright; 
    } 

    public Route getRoute() { 
     return this.route; 
    } 

    public void setRoute(Route route) { 
     this.route = route; 
    } 
} 
package com.example.my**jakcontest;** 

    import java.util.List; 

    public class Direction{ 

    private String _branch; 
    private String _name; 
    private String _tag; 
    private String _title; 
    private String _useForUI; 
    private List<Stop> stop; 

    public String get_branch(){ 
     return this._branch; 
    } 
    public void set_branch(String _branch){ 
     this._branch = _branch; 
    } 
    public String get_name(){ 
     return this._name; 
    } 
    public void set_name(String _name){ 
     this._name = _name; 
    } 
    public String get_tag(){ 
     return this._tag; 
    } 
    public void set_tag(String _tag){ 
     this._tag = _tag; 
    } 
    public String get_title(){ 
     return this._title; 
    } 
    public void set_title(String _title){ 
     this._title = _title; 
    } 
    public String get_useForUI(){ 
     return this._useForUI; 
    } 
    public void set_useForUI(String _useForUI){ 
     this._useForUI = _useForUI; 
    } 
    public List<Stop> getStop(){ 
     return this.stop; 
    } 
    public void setStop(List<Stop> stop){ 
     this.stop = stop; 
    } 
} 

비동기 작업

XStream x = new XStream(); 
        x.alias("body", Body.class); 
        x.alias("stop", Stop.class); 
        x.alias("route", Route.class); 
        x.alias("direction", Direction.class); 
        x.alias("path", Path.class); 
        x.alias("point", Point.class); 

        x.addImplicitCollection(Route.class, "stop"); 
        x.addImplicitCollection(Route.class, "direction"); 
        x.addImplicitCollection(Route.class, "path"); 
        x.addImplicitCollection(Direction.class, "stop"); 
        x.addImplicitCollection(Path.class, "point"); 

        Body object = (Body) x.fromXML(httpResponse.getEntity() 
        .getContent()); 

        // Function converts XML to String 

        String xml = convertStreamToString(httpResponse.getEntity() 
          .getContent()); 

        Body b = (Body) x.fromXML(xml); 

난 내가 "B"모든 클래스하지만 객체가 널 지르고있어.

+0

은 알려 주시기 바랍니다 링크를 참조하면 XML에서 자바 클래스를 만들 수있는 도구를 온라인으로 제공. 그게 좋을거야. – user3093833

답변

관련 문제