Question

I'm writing an Android application and I want to provide the ability for the end user to create collections of objects from a class hierarchy with XML. For example: I'd like the user to be able to provide something like this arbitrary example:

<animals>
    <dogs>
        <bulldog name="Frank" />
        <mastif name="George" />
    </dogs>
    <cats>
         <mainecoon name="Alex" age="3" />
    </cats>
</animals>

I'd like to validate this user-provided XML against a schema I create, and then create instances of these classes based on the XML. The question I have is that if I add a subclass.. say reptile, I have to change the implementation for the XML parser as well as the schema to validate the XML. This seems like bad practice because a change in the class hierarchy mandates a change in other places. Is there anyway to minimize the impact of adding a type to my Android app with regard to the XML the user can provide and the Schema that validates it?

Was it helpful?

Solution

I found a solution. Using annotations and a framework like JAXB or Simple will let you serialize/deserialize objects to/from xml. JAXB can be run on Android which could be a solution. link

But JAXB is pretty heavy weight so I'm favoring Simple because it is more lightweight.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top