Location: PHPKode > projects > FarODP > farodp/includes/xml/FarODPXMLObject.php
<?php

class FarODPXMLObject extends AbstractVisitor {
	var $result;
	var $curCat;
	var $curElement = '';
	var $xml;
	var $level = 0;
	var $priority = 0;
	
	function FarODPXMLObject($cat) {
	    $this->xml = new XMLObject();
	    $this->xml->openElement(0, 'farodp', array('spec' => '1.0'));
	    $this->xml->openElement(1, 'category', array('name' => catPath($cat)));
	}
	
	function getXML() {
		return '<?xml version="1.0" encoding="UTF-8" ?' . '>' . "\n" .
	    $this->xml->getXML();
	}
	
	function close($level) {
	}

	function commonVisit($n, $level) {

	    if ($level < $this->level) {
	        $diff = $this->level - $level;
	    	$this->xml->close($diff - 1);
		} else if ($this->level === $level) {
		}
	    $this->level = $level;
	}

	function visitODPNode($n, $level) {
		$this->commonVisit($n, $level);
	}

	function visitCurCat($n, $level) {
		$this->commonVisit($n, $level);
	    $this->curCat = $n->cat;
	}

	/* A to Z list. */

	function visitAToZ($n, $level) {
		$this->commonVisit($n, $level);
	}

	function visitAToZItem($n, $level) {
		$this->xml->addElement('letter', array('name' => $n->name, 'target' => catPath($n->cat)));
		$this->commonVisit($n, $level);
	}

	/* Browse categories */

	function visitBrowseCategoryContainer($n, $level) {
		$this->commonVisit($n, $level);
	}

	function visitBrowseCategorySection($n, $level) {
		$this->commonVisit($n, $level);
		$this->priority++;
	}

	function visitBrowseCategory($n, $level) {
		$this->commonVisit($n, $level);
	    $this->xml->addElement('subcat', array('name' => $n->name, 'priority' => $this->priority,
	        'items' => $n->count));
	}

	function visitBrowseCategorySymbolic($n, $level) {
		$this->commonVisit($n, $level);
	    $this->xml->addElement('symlink', array('name' => $n->name, 'target' => catPath($n->cat),
	        'priority' => $this->priority,
	        'items' => $n->count));
	}
	
	function visitBrowseCategoryRelated($n, $level) {
		$this->xml->addElement('related', array('target' => catPath($n->cat), 'items' => $n->count));
	}

	/* Listings */
	
	function visitBrowseListingContainer($n, $level) {
		$this->commonVisit($n, $level);
	
	}

	function visitBrowseListing($n, $level) {
		$this->commonVisit($n, $level);
	    if ($n->isStar) {
			$this->xml->openElement($level, 'item', array('about' => $n->url, 'star' => '1'));
	    } else {
			$this->xml->openElement($level, 'item', array('about' => $n->url));
	    }
	    $this->xml->openElement($level, 'title');
	    $this->xml->addText($n->title);
     	$this->xml->closeElement();
	    $this->xml->openElement($level, 'desc');
	    $this->xml->addText($n->description);
	    $this->xml->closeElement();
	    $this->xml->closeElement();
	}

	function visitCategoryRelatedSection($n, $level) {
		$this->commonVisit($n, $level);

	}
	
	function visitSearchListingContainer($n, $level) {
		$this->commonVisit($n, $level);
	
	}

	function visitSearchListing($n, $level) {
		$this->commonVisit($n, $level);

	}
}

?>
Return current item: FarODP