XMLPull - Split node parsing between base class and derived classes

ExpertHelps

New Member
I'm looking at XML Pull parsing approach to parse the following document:\[code\]<layout> <button height="20" width="20" text="Hello world" /> <image height="10" width="10" img="foo.png" /></layout>\[/code\]and produce corresponding Java objects. I have an abstract base class Component, whose responsibility would be to describe a generic Component having an height and a width, and it should be able to get these values by parsing the corresponding XML attributes of the passed "node" (more precisely, parser pointing to the node).Deriving from Component, I have two concrete classes Button and Image, which add, respectively, a text and an image. They should be able to initialize these values from XML attributes.This is a sketch of classes implementation:\[code\]public abstract class Component { public int width; public int height; public Component(XmlPullParser parser) { //TODO ??? }}public class Button extends Component { public String text; public Button(XmlPullParser parser) { super(parser); //TODO ??? }}public class Image extends Component { public String img; public Image(XmlPullParser parser) { super(parser); //TODO ??? }}\[/code\]The question is, how to implement the parsing to obtain this behaviour? My main concern is that when you call nextTag() on the parser, the parser itself is "modified". So, if the Component superclass reads the whole node to get the width and height (call to the super() constructor), how could the derived class read the same node to initialize itself?Thanks ;)
 
Back
Top