Simple framework skip soap envelope and body

前端 未结 2 1788
眼角桃花
眼角桃花 2021-01-18 21:27

I\'m using RetroFit and Simple XML Framework in Android to model a SOAP response that looks like this:

XML:

&l         


        
2条回答
  •  滥情空心
    2021-01-18 22:06

    the simple way is use @path , example i want get Route from node Soap/Body/BuslocationResponse/Vehicles/Vehicle

    Response.java

    @Root(name = "soap:Envelope", strict = false)
    public class Response {
       @Element(name = "Route")
       @Path("Body/BuslocationResponse/Vehicles/Vehicle")
       private int route;
    
       public int getRoute() {
        return route;
       }
    }
    

    Main.java

    class Main {
    public static void main(String args[]) {
        String xml = "\n" +
                "\n" +
                "    \n" +
                "        1.0\n" +
                "        0\n" +
                "        \n" +
                "            801\n" +
                "            N\n" +
                "        \n" +
                "        \n" +
                "            \n" +
                "                801\n" +
                "                N\n" +
                "                09:42 PM\n" +
                "                5007\n" +
                "                801-06\n" +
                "                -2\n" +
                "                S\n" +
                "                Y\n" +
                "                N\n" +
                "                N\n" +
                "                Y\n" +
                "                20.61\n" +
                "                 3\n" +
                "                44916\n" +
                "                \n" +
                "                    30.221222,-97.765007\n" +
                "                    30.218363,-97.766747\n" +
                "                    30.215282,-97.768715\n" +
                "                    30.212505,-97.770485\n" +
                "                    30.204943,-97.774765\n" +
                "                    30.204035,-97.775078\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "\n" +
                "\n" +
                "";
    
        try {
            Serializer serializer = new Persister();
            Response r = serializer.read(Response.class, xml);
            System.out.println("route: " + r.getRoute());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    } 
    

    Result:

    /usr/lib/jvm/java-8-oracle/bin/java....
    route: 801
    Process finished with exit code 0
    

提交回复
热议问题