I need to create a simple XML parser using a state machine. I know I'm going to be user push_back when i get a valid tag and pop_back to start verifying the tag when I reach </ but I am unsure as to how to go about creating the state machine for this. The problem I am having is the fact that since I am reading char by char, if I get the char < , I always have to read again to see if the / is there or what. Anyone got a heads up on how to create a complex parser using a state machine like this?
there are a couple of open source xml parsers. have a look atxerces (complicated) and tinyxml (a bit simpler) for ideas.
actually parsing xml is not that difficult, but it gets a lot harder if you have to do validation.
as for the state machine, I'd start by listing all the states you can be in and then I'd diagram the valid transitions between them. The code should flow reasonably easily from that.