Though the example below may seem long and complicated it's really not that bad, much of it is FYI for the beginners. You can skip to the bottom of this page to simply copy and paste the final code in one shot.

Goal: Using the en-ca-v1_demo database structure as your starting point (currently unavailable) lets say you want to list the names and corresponding ids of all the regions found in the World Wide Travel Guide's (WWTG) XML database on your own website.

Requirements: None other than a PHP enabled web server that is permitted to place fsockopen() calls to outside web services.

Recommendations: It is easier to build and execute custom code if you take advantage of the pre-built configuration settings and libraries already found inside the _config.php and _library.php files that come with a copy of any full or demo version of the WWTG templates. You can download a copy of the en-ca-v1_demo templates here; http://travelagentsoftware.com/forum/demoInfo.php. This example will presume that you have access to these two files and are using them in your own code. If you are not planning to 'include' these two files in your code then you'll have to refer to these examples and add the appropriate information/functions where necessary.

First off lets open the PHP code brackets and include our two resource files.

include_once "wwtg/_config.php";
include_once "wwtg/_library.php";



Next we need to build our XML request and store it inside a variable.

$XMLRequest = "<wwtgRequest>
	<subscriptionId>" . $wwtg_cfg["subscriptionId"] . "</subscriptionId>
	<request>
		<sql>FROM `regions`</sql>
		<returnFields>
			<name>id</name>
			<name>name</name>
		</returnFields>
	</request>
</wwtgRequest>";



Next we call the XML cache checking and feed requesting function call wwtg_getXML() from the _library.php file and store the results in another variable.

$regionsResponse = wwtg_getXML($XMLRequest);



To make the data readable we will need to further extract it into a custom array. We accomplish this by stepping through the original array, record by record, looking for what we want to keep and extracting it into a much smaller array. Here is how we did it for the WWTG templates.

if($regionsResponse) {
	for($i = 0; $i < count($regionsResponse); $i++) {
		if($regionsResponse[$i]["tag"] == "REQUEST" && $regionsResponse[$i]["type"] == "open") {
			$i++;
			while(!($regionsResponse[$i]["tag"] == "REQUEST" && $regionsResponse[$i]["type"] == "close")) {
				if($regionsResponse[$i]["tag"] == "SQL" && $regionsResponse[$i]["type"] == "open") {
					$sqlRequest = $regionsResponse[$i]["attributes"]["REQUEST"];
					$i++;
					// This sets up the starting point for a new array used to hold captured values for ease of later output.
					$key = 0;
					while(!($regionsResponse[$i]["tag"] == "SQL" && $regionsResponse[$i]["type"] == "close")) {
						if($regionsResponse[$i]["tag"] == "RECORD" && $regionsResponse[$i]["type"] == "open") {
							$i++;
							while(!($regionsResponse[$i]["tag"] == "RECORD" && $regionsResponse[$i]["type"] == "close")) {
								if($regionsResponse[$i]["tag"] == "ID" && $regionsResponse[$i]["type"] == "complete") {
									$id = $regionsResponse[$i]["value"];
									$regionsArray[$key]["id"] = $id;
								} elseif($regionsResponse[$i]["tag"] == "NAME" && $regionsResponse[$i]["type"] == "complete") {
									$name = $regionsResponse[$i]["value"];
									$regionsArray[$key]["name"] = $name;
									$key++;
								}
								$i++;
							}
						}
						$i++;
					}
				}
				$i++;
			}
		}
	}
}



All that's left to do now is breakout/use the final array somewhere in your website. Here is some code that writes the results into a table.
<table border="1" cellpadding="5" cellspacing="0">
	<tr>
		<td colspan="2" style="font-weight:bold; text-align:center;">Regious of the World</td>
	</tr>
	<tr style="font-weight:bold; text-align:center;">
		<td>ID</td>
		<td>Name</td>
	</tr>
	<?for($i = 0; $i < count($XMLArray); $i++):?>
<tr>
		<td><?=$XMLArray[$i]["id"];?></td>
		<td><?=$XMLArray[$i]["name"];?></td>
	</tr>
	<?endfor?>
</table>




To summarize, here is a copy of all the code in a unified copy and paste.
<?
include_once "wwtg/_config.php";
include_once "wwtg/_library.php";

$XMLRequest = "<wwtgRequest>
	<subscriptionId>" . $wwtg_cfg["subscriptionId"] . "</subscriptionId>
	<request>
		<sql>FROM `regions`</sql>
		<returnFields>
			<name>id</name>
			<name>name</name>
		</returnFields>
	</request>
</wwtgRequest>";

$regionsResponse = wwtg_getXML($XMLRequest);
//echo '<br /><pre>'; print_r($regionsResponse); echo '</pre><br />';

if($regionsResponse) {
	for($i = 0; $i < count($regionsResponse); $i++) {
		if($regionsResponse[$i]["tag"] == "REQUEST" && $regionsResponse[$i]["type"] == "open") {
			$i++;
			while(!($regionsResponse[$i]["tag"] == "REQUEST" && $regionsResponse[$i]["type"] == "close")) {
				if($regionsResponse[$i]["tag"] == "SQL" && $regionsResponse[$i]["type"] == "open") {
					$sqlRequest = $regionsResponse[$i]["attributes"]["REQUEST"];
					$i++;
					// This sets up the starting point for a new array used to hold captured values for ease of later output.
					$key = 0;
					while(!($regionsResponse[$i]["tag"] == "SQL" && $regionsResponse[$i]["type"] == "close")) {
						if($regionsResponse[$i]["tag"] == "RECORD" && $regionsResponse[$i]["type"] == "open") {
							$i++;
							while(!($regionsResponse[$i]["tag"] == "RECORD" && $regionsResponse[$i]["type"] == "close")) {
								if($regionsResponse[$i]["tag"] == "ID" && $regionsResponse[$i]["type"] == "complete") {
									$id = $regionsResponse[$i]["value"];
									$regionsArray[$key]["id"] = $id;
								} elseif($regionsResponse[$i]["tag"] == "NAME" && $regionsResponse[$i]["type"] == "complete") {
									$name = $regionsResponse[$i]["value"];
									$regionsArray[$key]["name"] = $name;
									$key++;
								}
								$i++;
							}
						}
						$i++;
					}
				}
				$i++;
			}
		}
	}
}
//echo '<br /><pre>'; print_r($regionsArray); echo '</pre><br />';
?>
<table border="1" cellpadding="5" cellspacing="0">
	<tr>
		<td colspan="2" style="font-weight:bold; text-align:center;">Regious of the World</td>
	</tr>
	<tr style="font-weight:bold; text-align:center;">
		<td>ID</td>
		<td>Name</td>
	</tr>
	<?for($i = 0; $i < count($regionsArray); $i++):?>
	<tr>
		<td><?=$regionsArray[$i]["id"];?></td>
		<td><?=$regionsArray[$i]["name"];?></td>
	</tr>
	<?endfor?>
</table>

See, nothing to it... :-)