Searching and Acting upon tags in a file.

Hi,

Im trying to make a tool that will read strings from files and place data from those files into classes and its datamembers based on what the tags before the data.

I know this explanation is pretty vague but bare with me a while and Ill try to explain further :P

My current problem is how I should check for tags in a stream and not just a char. I have the book "Object-Oriented programming in C++" by Robert Lafore and I cannot find any information that makes my problems any easier.

Here is a example on how a string looks like(its unsorted originally, but I have sorted it for easier reading)

<RaidInfo>
<key>1231184276</key>
<start>1231184276</start>
<end>1231229714</end>
<zone>Naxxramas</zone>

<PlayerInfos>
<key1>
<name>name1</name>
<race>Gnome</race>
<guild>guildname</guild>
<sex>3</sex>
<class>WARRIOR</class>
<level>80</level>
</key1>
<key2>
<name>name2</name>
<race>NightElf</race>
<guild>guildname</guild>
<sex>2</sex>
<class>DRUID</class>
<level>80</level>
</key2>
.......
.......
.......
</raidinfo>

Yes, its a tool for reading strings from a WoW addon called Raidtracker.
This is just a very small part of a string, I have a small string that is on 15k chars.

I was planning on having each of these strings saved into separate files under a directory(the tool will then read all files in this directory, validate if its a raid by checking for <raidinfo>)

At first I started making a search function for a string, I managed to search through a string and find start tags, end tags and pointers to each.
At some point I realised I needed to do this for the stream instead of a string. Now, I have a real problem:

How do I search for these tags in a stream?
say I want to:
1. find a tag named <attendees>.
2. find <name>.
3. add what is directly after <name>into a spot in a array that is inside a class.
4. stop writing when I find the tag </name>.
5. continue to write to this array until I arrive at </attendees>

Sadly there is no set size of these parts inside the file, so I cannot just write the whole thing into the class(cause the string will wary in size and the amount of <name></name> tags will vary from file to file)

Ill gladly add code and whats inside a file if u guys need it to see what Im trying to do, but Its pretty long so I thought Id leave it out of here for clearity(as if my explanation wasnt vague enough :P)
Get an XML library and use that :)
Seconded. That data will be tricky to parse.

Two ideas come to mind immediately:

1. Write a finite state machine that reads the tags. I think there are libraries that will even help you do this and I'm sure there are some that already exist for XML.

2. Write a recursive parser that stores the data in some kind of composite structure. Note that this will be easy if all of the tags have matching closing tags; if not, everything will become a child of the unclosed tags...
Last edited on
wowowowoow, hold on :P

I posted in beginner forum for a reason :P

Im currently taking a programming education, but Im only on the 1st year :P I dont even what a finite state machine is :P I also more or less JUST began to be able to read and understand MS's explanations of their library functions :S Even finding a new library sounds daunting at best :S

So, there is basically no good way to do this through stream? Should I go back to the original idea of having a stream converted into a string and find the tags from there?
Yea, read it in and parse it manually as strings. A real PITA but at your level the best method.
Topic archived. No new replies allowed.