<?
/**
* Class xmlitem for class XML for weblication
* @author Andreas Altendorfer <hide@address.com>
* @date 2003-12-06
*/
class xmlitem
{
var $name;
var $data;
var $attrs;
var $children;
var $cnt_children;
var $prevItem;
var $parser;
var $level;
//////////////////////////////////////////////////////////////////////
// INTERFACE
//////////////////////////////////////////////////////////////////////
// Constructor
function xmlitem($parser, $parentItem, $name, &$attrs ) {
$this->parser = $parser;
$this->prevItem = $parentItem;
$this->name = $name;
$this->attrs= $attrs;
$this->cnt_children = 0;
$this->children = array();
$this->level = $depth[$parser];
}
function endElement() {
// dummy
}
function load() {
return( true );
}
function addChild( $item ) {
global $xml_item;
// $r = new xmlitem( $this->parser, $item->prevItem, $item->name, $item->attrs );
$this->children[] = $item;
//print "Added $item->name to $this->name ($this->name now have ".count( $this->children )." child/ren\n";
}
function getAttr( $name ) {
return( $this->attrs[strtoupper($name)] );
}
function findElement( $name ) {
$found = array();
if ( $this->findElements($found,$name) == 1 ) {
return( $found[0] );
} else {
return( false );
}
}
function findElements( &$a, $name ) {
reset( $this->children );
$cnt = 0;
while( list( $key, $e ) = each( $this->children ) ) {
if ( strtoupper($e->name) == strtoupper($name) ) {
$a[$cnt] = new xmlitem( $e->parser, $e->prevItem, $e->name, $e->attrs );
$a[$cnt]->children = $e->children;
$a[$cnt]->data = $e->data;
$cnt++;
}
}
return( $cnt );
}
function display() {
$rc = "";
Append( $rc, "<table border=1 cellspacing=10 cellpadding=0
width=100%><tr><td collspan=2 bgcolor=white><b>" .
$this->name . "</b>");
if ( $this->data > "" ) { Append( $rc, "<br>" . $this->data ); }
Append( $rc, "</td></tr>" );
// Attributes
reset( $this->attrs );
while( list( $key, $val ) = each( $this->attrs ) ) {
Append( $rc, sprintf( "<tr><td align=left bgcolor=lightgrey
cellpadding=2>%s = %s</td></tr>\n", $key, $val ));
}
// Children
if ( $this->children ) {
Append( $rc, "<tr><td collspan=2 valign=top>" );
reset( $this->children );
while( list( $key, $e ) = each( $this->children ) ) {
Append( $rc, $e->display() );
}
Append( $rc , "</td></tr>" );
}
Append( $rc, "</table>" );
return( $rc );
}
//////////////////////////////////////////////////////////////////////
// PRIVATE
//////////////////////////////////////////////////////////////////////
} //- class xml
?>