I have to parse some xml with java SAX parser. As I was busy, I saw that the state pattern could be used here.
There are clear states and state transitions defined, resembling the structure of the xml document.
To implement the state pattern, I have to define a interface (or abstract class). The most obvious interface methods would be:
public void startElement(String elementName);
public void endElement(String elementName);
But the problem I encounter is how to return the information. I need the information from several levels in the xml document in one structure.
This is a part of the xml document
<chessboard>
<white>
<king>
<position>
<x>e</x>
<y>1</y>
</position>
</king>
<pawns>
<pawn id="1">
<position>
<x>e</x>
<y>2</y>
</position>
</pawn>
<pawn id="1">
<position>
<x>f</x>
<y>2</y>
</position>
</pawn>
</pawns>
</white>
</chessboard>
Is my assumption right that the state patterns fits here? And if so, what is the best way to implement it here?