# Little help on a TxT Phraser (for WoW)

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am a self taught programmer as a hobby (that is why I am asking for help he he So please do not jump on me if this is a simple thing. Basicaly I am trying to write a phraser that will read a txt file and output the infomation into a formatted HTML page. I play a game called World of Warcraft and I am using a mod for it called GuildTools witch can out put the guild roster as a txt file. I wish to use that infomation to build a formatted HTML page. I am pretty sure i know how to read, move and use the data in the txt file but I am nto sure about how to save out a formated HTML file that uses the data in the txt file. Can anyone send me some links of tutorials that deal with this or mabey offer some helpful sugestions? <More info> The text file can output any txt string containing the values you assign it.... on each line, for each guild member. Example:- Hunter level 60 toonname mage level 60 toonname warlock level 60 toonname pally level 60 toonname The mod can oput put the text file any way I like it , so I can place markers on the file for the txt phraser program to look for. Example:- @Hunter #level 60 $toonname @mage #level 60$toonname @warlock #level 60 $toonname @pally #level 60$toonname Any help would be very nice, thanks in advance.

##### Share on other sites
Read the file in line by line then word by word. For example:
// Warning Pseudocode!stringstream sLine;string line;ifstream file("roster.txt");vector<string>singleWords;while(getline(file, line)){    sLine(line);    string word;    while(line >> word)    {        singleWords.push_back(word);    }}

Then each index in the vector will hold a sinlge 'word'. Just attach the needed html to each word and viola. Sorta...

##### Share on other sites
Thanks for the help but I am pretty sure the code i have can read the file and load it up into orginised and sorted vector arrays.... . .

What i do not know how to do it write a HTML file out and insert into it the data from teh arrays.

I basicaly want to write a html file and ten insert the data into it.. how would I go about that?

Quote:
 Original post by jyujinkaiI am pretty sure i know how to read, move and use the data in the txt file but I am nto sure about how to save out a formated HTML file that uses the data in the txt file

##### Share on other sites
Well if you read each 'word' in seperatly all you need to do then is combine that word with html. Strings are your friend.

Ok, lets go over what we 'know'.

1: There are 4 words per character. EX: 1: Hunter, 2: Level, 3: 60, 4: toonname
2: The vector will hold them in order.
3: 'string' variables are sexy.
4: 'vector' arrays are sexy.

Now if things are always like that we can set up a loop to extract 4 entries from the vector at a time and add html to them as needed, then write that line to a file. So let's set us up a 'for' loop and some logic.

	string line:		// Holds each HTML'ed line	int maxFour = 0;	// Counts every items read from the vector	ofstream outFile("WoW.htm")	// The name of your new hmtl file	// Loops once for every item in vectorString	for(int i = 0; i < vectorString.size(); i++)	{		maxFour++; // adds one for ever word				switch(maxFour)		{		case 0:		// Character class			line += "<i>" + vectorString + "</i>:";                        break;		case 1:		// The word "level"			line += " lvl-";                        break;		case 2:		// Actual level			line += vectorString;                        break;		case 3:		// Character name and last entry                    line += "<b> " + vectorString + "</b>";                    outFile << line << "<br> \n";	// Writes a line to WoW.htm                    maxFour = 0;    // Resets maxFour		    line = "";      // clears the current line                    break;		default:			break;		}    }

Result:
Hunter: lvl-60 toonname
You can of course go hog wild with how you want to output your html. But that should get you started.

EDIT: Code was all kinds of nasty.

[Edited by - -JetSirus- on July 28, 2006 3:40:23 AM]

##### Share on other sites
so you are saying that I should write the HTML as I normaly would and then turn it into one continual string. After that I then simply cut and past strings together so the output has all the infomation i need?

I will haev a play with this on the morrow and let you know how it works out....

Cheers

##### Share on other sites
Baaaaaaasically.

Remember that HTML has a sort of tree structure. You can write things as you go, so as not to accumulate the whole thing in memory, but you'll want to organize the writing process to make sure that you write everything that you need for the HTML, in the right order.

This will likely involve making functions that write out an html "section" - from the opening tag to the closing tag. Depending on what section you are writing, you can call functions to output the body of the tag from within, possibly recursively.

typedef std::map<std::string, std::string> attributeMap;ostream& writeHtml(ostream& os, const std::string& tag, const attributeMap& attributes) {  os << "<" << tag;  for (attributeMap::iterator it = attributes.begin(); it != attributes.end(); ++it) {    os << " " << it->first << "='" << it->second << "'";  }  os << ">\n";  fillSection(tag); // call to outside code to write the HTML that's between  // the tags. It might call back to writeHtml, if appropriate.  return os << "</" << tag << ">\n";}

##### Share on other sites
Ever worked in Perl? It's a great language for tasks like this. http://www.perl.com/.

#super quick and dirty
#Basic idea, might need some tweaking.
open(FILE,'Orders.txt');

print "intro HTML"
while(<FILE>){
chomp;
my @Line=split(/\t/,$_); for each my$Unit (@Line){
}
}
print "closing HTML"

Char