Best approach to parse large non-xml data

Nate Bross

Well-known member
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
I have this data (below). I need to pull out several bits of data. In the Example below, I need to pull the values:
The Paradox
["Guild"] = The Paradox
["Motd"]
and then this data from each member
["Sindogg"] = {
["Note"] = "",
["Zone"] = "Westfall",
["Group"] = "no",
["Class"] = "Druid",
["Level"] = 24,
["Name"] = "Sindogg",
["Rank"] = "Alt",
{

Any ideas, C#, VB are welcome.

Code:
myProfile = {
	["Malorne"] = {
		["Guild"] = {
			["Guild"] = "The Paradox",
			["Date"] = "12/04/06 18:21:16",
			["Hour"] = 18,
			["Locale"] = "enUS",
			["Minute"] = 21,
			["Motd"] = "Download Teamspeak ([url]www.goteamspeak.com[/url]) TS hostname=theparadox.shacknet.nu:8767. ZG 12.09.06 we need EVERYONE there",
			["Created"] = "11-9-2006",
			["DateUTC"] = "12/05/06 00:21:16",
			["DateExtracted"] = "12/04/06 18:21:16",
			["Members"] = {
				["Sindogg"] = {
					["Note"] = "",
					["Zone"] = "Westfall",
					["Group"] = "no",
					["Class"] = "Druid",
					["LastOnline"] = {
						["Day"] = 10,
						["Month"] = 0,
						["Hour"] = 4,
						["Year"] = 0,
					},
					["RankIndex"] = 7,
					["OfficerNote"] = "",
					["Status"] = "",
					["Level"] = 24,
					["Name"] = "Sindogg",
					["Rank"] = "Alt",
				},
				["Sushiroll"] = {
					["Note"] = "",
					["Zone"] = "Ironforge",
					["Group"] = "no",
					["Class"] = "Rogue",
					["LastOnline"] = {
						["Day"] = 0,
						["Month"] = 0,
						["Hour"] = 22,
						["Year"] = 0,
					},
					["RankIndex"] = 6,
					["OfficerNote"] = "",
					["Status"] = "",
					["Level"] = 45,
					["Name"] = "Sushiroll",
					["Rank"] = "Initiate",
				},
				["Wheelz"] = {
					["Note"] = "",
					["Zone"] = "Darkshore",
					["Group"] = "no",
					["Class"] = "Hunter",
					["LastOnline"] = {
						["Day"] = 14,
						["Month"] = 0,
						["Hour"] = 2,
						["Year"] = 0,
					},
					["RankIndex"] = 5,
					["OfficerNote"] = "",
					["Status"] = "",
					["Level"] = 18,
					["Name"] = "Wheelz",
					["Rank"] = "Member",
				},
				["Nubber"] = {
					["Note"] = "",
					["Zone"] = "Stormwind City",
					["Group"] = "no",
					["Class"] = "Warrior",
					["LastOnline"] = {
						["Day"] = 2,
						["Month"] = 0,
						["Hour"] = 18,
						["Year"] = 0,
					},
					["RankIndex"] = 4,
					["OfficerNote"] = "",
					["Status"] = "",
					["Level"] = 16,
					["Name"] = "Nubber",
					["Rank"] = "Charter Member",
				},
			["NumMembers"] = 91,
			["NumAccounts"] = "71",
			["Info"] = "ZG attempts begin saturday!!!!!!!!!!\n\nTemp website\nhttp://www.guildportal.com/Guild.aspx?GuildID=129956&TabID=1106625\n\n\n\n\nTHE PARADOX TEAMSPEAK SERVER\n\ntheparadox.shacknet.nu:8767\n",
			["Faction"] = "Alliance",
			["DBversion"] = "1.6.0",
			["Version"] = "1.6.0",
			["GPprovider"] = "rpgo",
			["GPversion"] = "1.6.0",
		},
	},
}
 
Strangly enough, I found a PhP example that is supposed to process that very data. I dont know any PhP, and I dont have an apache server to test it out.

Heres the of the function that stores the data in a sql database. If necessary, I can attach the entire php file, but its too big to post.

Code:
function processGuildRoster($myProfile)
{
	global $wowdb, $roster_conf, $wordings;

	$wowdb->resetMessages();

	if( is_array($myProfile) )
	{
		foreach( array_keys($myProfile) as $realm_name )
		{
			// Only allow realms specified in config
			if( $realm_name == $roster_conf[server_name])
			{
				$realm = $myProfile[$realm_name];
				$guild = $realm[Guild];
				if( is_array($guild) )
				{
					$guildName = $guild[Guild];
					// Only allow the guild specified in config
					if( $roster_conf[guild_name] == $guildName )
					{
						// GP Version Detection, dont allow lower than minVer
						if( $guild[DBversion] >= $roster_conf[minGPver] )
						{
							// make hour between 0 and 23 and minute between 0 and 60
							$guildHour= intval($guild[Hour]);
							$guildMinute= intval($guild[Minute]);

							// take the current time and get the offset. Upload must occur same day that roster was obtained
							$currentTimestamp = mktime($guildHour,$guildMinute,0);
							$currentTime = getDate($currentTimestamp);

							// Update the guild
							$guildId = $wowdb->update_guild($realm_name, $guildName, $currentTime, $guild);
							$guildMembers = $guild[Members];

							// update the list of guild members
							$guild_output = ;
							foreach(array_keys($guildMembers) as $char_name)
							{
								$char = $guildMembers[$char_name];
								$wowdb->update_guild_member($guildId, $char_name, $char, $currentTimestamp);
								$guild_output .= $wowdb->getMessages();
								$wowdb->resetMessages();

								// Start update triggers
								if( $roster_conf[use_update_triggers] )
								{
									$guild_output .= start_update_trigger($char_name,guild);
								}
							}
							// Remove the members who were not in this list
							$wowdb->remove_guild_members($guildId, $currentTime);
							$wowdb->remove_guild_members_id($guildId);

							$guild_output .= $wowdb->getMessages();
							$wowdb->resetMessages();
							$guild_output .= "\n";
							$output .= "<strong>Updating Guild [<span class=\"orange\">$guildName]</strong>\n\n";
							$output .= "<strong>Member Log</strong>\n\n".
								"Updated: ".$wowdb->membersupdated."\n".
								"Added: ".$wowdb->membersadded."\n".
								"Removed: ".$wowdb->membersremoved."\n".
								"\n<br />\n";
							$output .= $guild_output;
						}
						else
						// GP Version not new enough
						{
							$output .= "<span class=\"red\">NOT Updating Guild list for $guildName<br />\n";
							$output .= "Data is from GuildProfiler v".$guild[DBversion]."<br />\n";
							$output .= $wordings[$roster_conf[roster_lang]][GPver_err]."<br />\n";
						}
					}
					else
					{
						$output .= sprintf($wordings[$roster_conf[roster_lang]][guild_nameNotFound],$guildName)."<br />\n";
					}
				}
				else
				{
					$output .= <span class="red">.$wordings[$roster_conf[roster_lang]][guild_addonNotFound].."<br />\n";
				}
			}
			else
			{
				$output .= $myProfile[$realm_name][Guild][Guild]. @ .$realm_name. .$wordings[$roster_conf[roster_lang]][ignored]."<br />\n";
			}
		}
	}
	return $output;
}
 
Back
Top