Parsing the use cases XML

Posted by Jad on June 11, 2007

I discussed the other day about writing the use cases. I also mentioned that I was going to write them all in XML so they could be easily parsed later on.

As you might have noticed by looking at only 3 use cases, it gets pretty long and hard to read in raw format, so first code had to be a parser for that.

Solution: Clean XML To Array by Ivan Enderlin, found on PHPClasses.

All you need is to download the lib.xml.php and create the a new file with the little code shown below.

<?php
include('lib.xml.php');
$xml = new Xml;
$out = $xml->parse('file.xml', 'FILE');
echo '<pre>'.print_r($out).'</pre>';
?>

All that was left to do was to parse it in an easy to read format. This will do for now as I don’t want to spend too much time on it.

<?php
include('lib.xml.php');
$xml = new Xml;
$out = $xml->parse('usercase.xml', 'FILE');
//echo '<pre>'.print_r($out).'</pre>';exit();

foreach ($out as $usecases) {
	for ($i=0; $i<count($usecases); $i++) {
		$usecase = $usecases[$i];

		echo '<div class="usecase">';
		echo '<h3>'.$usecase[name].': '.$usecase[description].'</h3>';
		echo '<p class="overview">';
		echo '<strong>Sitting:</strong> '.$usecase[sitting].'<br />';
		echo '<strong>Primary Actor:</strong> '.$usecase[primaryactor].'<br />';
		echo '<strong>Scope:</strong> '.$usecase[scope].'<br />';
		echo '<strong>Level:</strong> '.$usecase[level].'<br />';
		echo '<strong>Minimal Guarantee:</strong> '.$usecase[minimalguarantee].'<br />';
		echo '<strong>Success Guarantee:</strong> '.$usecase[successguarantee].'<br />';
		echo '</p>';

		echo '<h4>Stakeholders</h4><p class="stakeholders">';
		foreach($usecase[stakeholders][stakeholder] as $id => $stakeHolder){
			echo '<strong>'.$stakeHolder.':</strong> '.$usecase[stakeholders][interest][$id].'<br />';
		}
		echo '</p>';

		echo '<h4>Scenario</h4><p class="scenario">';
		if(is_array($usecase[scenario][step])){
			foreach($usecase[scenario][step] as $id => $step) echo $id.'. '.$step.'<br />';
		} else {
			echo $usecase[scenario][step];
		}
		echo '</p>';

		echo '<h4>Extensions</h4><p class="extensions">';
		foreach($usecase[extensions][extension] as $id => $extension){
			echo '<strong>Extends:</strong> '.$extension['extends'].' ('.$usecase[scenario][step][$extension['extends']].')<br />';
			echo $extension['xcase'].'<br />';
			echo '<strong>Steps:</strong><ol>';
			if(is_array($extension['step'])){
				foreach($extension['step'] as $id => $step) echo $id.'. '.$step.'<br />';
			} else {
				echo $extension['step'];
			}
			echo '</ol>';
		}
		echo '</p>';
	}
}

?>
Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Ivan Enderlin Sat, 16 Jun 2007 00:52:02 EDT

    Glad to have helped you :) Thanks for the trackback ;-)

Comments