Thread: XML Parser

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    104

    Unhappy XML Parser

    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?

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    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.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SAX XML Parser
    By magic.mike in forum C++ Programming
    Replies: 1
    Last Post: 12-24-2008, 09:52 AM
  2. Replies: 2
    Last Post: 11-30-2006, 08:04 AM
  3. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 09:54 AM
  4. xml parser: recommendations?
    By captain-cat in forum C Programming
    Replies: 1
    Last Post: 07-26-2004, 09:54 AM
  5. Problem with Apache XML C++ Parser library
    By gandalf_bar in forum C++ Programming
    Replies: 2
    Last Post: 07-21-2004, 09:42 AM