Design advice for xml parser

1.5k views Asked by At

I have an xml data. From this data I need to create objects. Till now I used one class for parsing xml data and managing object state. I can see that cohesion of class is very low. So I want to give parsing responsibility to another class. As a simple idea I may use Factory Pattern for xml parsing and creating objects from xml data(My objects have a common base class). But how should I return created objects to consumer class. Container class object instance(list,map etc.)? One by one(when a node parsed)?

I am open to different desing advices.

2

There are 2 answers

2
yankee On

You may want to check libraries that do things like this for you. For instance simple: http://simple.sourceforge.net or JAXB: http://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding

3
Sean On

There's got to be an existing parser for your language/platform. My advice is to ask yourself if you really need to reinvent something like this.