Computer Science Canada File Parser that uses <tags> |
Author: | ericfourfour [ Mon Sep 04, 2006 12:50 am ] | ||||||||||||
Post subject: | File Parser that uses <tags> | ||||||||||||
This program is a file parser. It is very usefull for practically every type of program. I would recommend you learning pointers and variable types before using this. What it allows you to do is load a file and then parse tags from it. For example: If you wanted to parse the tag <cash>, you would simply call the function parse_tag with "cash" as the first parameter and it would return the value in between <cash> and </cash> as a variable type called str_array which is just a record that contains an array of strings and the upper bound. So now your function call looks like this:
What if you have more than one tag in the file named "cash"? Well, the second parameter in the parse_tag function is the tag number. If you want the second "cash" then you would use 2 as the tag number. If you wanted the first, third or even tength tag you would use 1, 3 or 10. For this example we will use the first. You function call now looks like this:
The third parameter can remain nil for now because that required some more explaining. So you are left with:
In a simple program you must first initialize the parser and load the file. To do this you would call the procedures:
There is one final thing to remember. The parser is a class so you need to have a pointer to it to use it. A simple program that parses this file,
and displays the name and age would look like this:
The code is over commented so it should be easy to understand. There is also a program named File Parser Test that shows all of the features of the parser and it is over commented aswell. Edit 1: spelling mistake Edit 2: added documentation Edit 3: fixed a mistake in FileParser (9 characters of one line were causing me a lot of grief ) |
Author: | NikG [ Mon Sep 04, 2006 2:50 am ] |
Post subject: | |
Nice idea! It looks like it could be easily implemented in other people's programs so that they could use this to load settings or information like that for their own progs (I'm guessing that's the point of xml?). |
Author: | bruized [ Thu Nov 02, 2006 6:49 pm ] |
Post subject: | |
It may be a little late (it's never too late to learn ) but I was just wondering what a "parser" was. |
Author: | [Gandalf] [ Fri Nov 03, 2006 4:11 am ] |
Post subject: | |
Learn to use Wikipedia. This is actually quite a useful program, good job ericfourfour. |
Author: | ericfourfour [ Fri Nov 03, 2006 8:20 am ] |
Post subject: | |
Quote: This is actually quite a useful program That's my goal for most of the things I submit. |