Text parsing - How?

Started by
6 comments, last by Structural 20 years, 6 months ago
How do you make a text parser in C/C++? For example something that parses XML to read menu data into the application. I''ve tried to work my way through an XML file with ssprintf, but I can''t even extract the contents between "<" and ">" tags. Perhaps these things are easier with something that supports regular expressions. Does anyone have tips on how I can do this? Preferably with standard C/C++ functionality.
STOP THE PLANET!! I WANT TO GET OFF!!
Advertisement
There are several XML parsers for C++ already, why not use one of them?
I don''t know any links, but I''m sure you''ll google them up.
And the price we paid was the price men have always paid for achieving paradise in this life -- we went soft, we lost our edge. - "Muad'Dib: Conversations" by the Princess Irulan
http://xml.apache.org/xerces-c/index.html



--
Dave Mikesell Software & Consulting
If what you need is a xml parser, save yourself the trouble and get xml markup library.
when you get time after checking out the xml parsers lex and yacc are neat too.
www.autodefrost.com/~travisSignature Virus cleaned by McAfee
It''s not that I only intend to do XML parsing, but I want to create a generic parser for scripts too.
STOP THE PLANET!! I WANT TO GET OFF!!
Go through each character, one at a time. Keep track of what "mode" your in. For example, if you read in a < but haven''t read a space or > yet, then you''re reading in a tag. Read the whole tag. Then match it up with your database of tags. If you reach a >, then end tag mode and enter regular text mode (which ends when it finds a < or one of the special characters like &. If you read a space, enter attribute mode (which ends you find a space, at which point you can enter attribute value mode, when you find an = and a "). In short, its quite complicated, unless you use lex and yacc like someone suggested (which are, in fact, generic parsers, not just used for XML and many programs use like lilypond, a nice program that generates sheet music in postscript format from code that describes the music).
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
Try "regular expressions".

This topic is closed to new replies.

Advertisement