Search code examples
javaandroidxml-parsingsimple-framework

Element is also a path name in class


I am trying to parse this XML:

<toteAdded id="R000000000012">
    <result code="S0000">Carrier added.</result>
</toteAdded>

using this Java code:

@Root(name="toteAdded")
public class ToteAddedTelegram extends Telegram {
    @Element
    String result;

    @Attribute
    @Path("result")
    private String code;

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return result;
    }
}

But I am getting this error:

Element 'result' is also a path name in class nl.minerall.sapphire.lib.telegrams.ToteAddedTelegram


Solution

  • You need to specify full path otherwise it will conflict with element name Result.

    @Attribute
    @Path("toteAdded/result")
    private String code;